Question

In: Computer Science

Program this in C thank you PROBLEM DESCRIPTION: Write a program to implement the following requirement:...

Program this in C thank you 

PROBLEM DESCRIPTION: Write a program to implement the following requirement:

The program will read from standard input two things
- a string str1 on the first line of stdin (this string may be an empty string)
- a string str2 on the second line of stdin (this string may be an empty string)
Note that stdin does not end with '\n'.

The program will output a string that is the concatenation of string str1 and string str2 such that any lower-case alphabet character (a-z) will be converted to upper-case and any upper-case alphabet character (A-Z) will be converted into lower-case. 

Note that stdout does not end with '\n'.

You cannot use any existing function from any library to do this concatenation. 

The maximum length of each input string is 100 characters


SAMPLE INTPUT

this is string one
This is string two

SAMPLE OUTPUT

THIS IS STRING ONEtHIS IS STRING TWO

Solutions

Expert Solution

Note: here each line of code is explained in the comment section, but if you any error or issue or dont understand the code feel free to ask me or post the issue.

(Remove that two scanf() comment code after fgets(), used only for checking the code).

myString.c

#include<stdio.h>
#define MAX_LIMIT 100

int main(){
    char str1[MAX_LIMIT], str2[MAX_LIMIT], res[2*MAX_LIMIT];
    int i = 0, k = 0;
    
    fgets(str1, MAX_LIMIT, stdin);
    fgets(str2, MAX_LIMIT, stdin);
    
  //  scanf("%[^\n]%*c",str1);
  //  scanf("%[^\n]%*c",str2);
    
    // for str1
    for(i=0; str1[i]!='\0'; i++){
        
        // store str1[i] to char ch
        char ch = str1[i];
        
        // if ch is between 'A' to 'Z'
        if(ch >= 'A' && ch <= 'Z')
            str1[i] += 32;
            
        // if ch is between 'a' to 'z'
        else if(ch >= 'a' && ch <= 'z')
             str1[i] -= 32;
             
        // check for next line ch if found continue loop     
        else if(ch == '\n')
             continue;     
             
        // store to res array
        res[k++] = str1[i];
         
    }
    
    // for str2 
    for(i=0; str2[i]!='\0'; i++){
        char ch = str2[i];
        
        // if ch is between 'A' to 'Z'
        if(ch >= 'A' && ch <= 'Z')
            str2[i] += 32;
            
        // if ch is between 'a' to 'z'
        else if(ch >= 'a' && ch <= 'z')
             str2[i] -= 32;
             
        // check for next line ch if found continue loop        
        else if(ch == '\n')
             continue;      
             
        // store to res array
        res[k++] = str2[i];
    }
    
    // store last char with null to print string before NULL value
    res[k] = '\0';
    
    // print res string
    printf("%s",res);
    
    return 0;
}

Related Solutions

Write and test a C program to implement Bubble Sort. . In your C program, you...
Write and test a C program to implement Bubble Sort. . In your C program, you should do: Implement the array use an integer pointer, get the size of the array from standard input and use the malloc function to allocate the required memory for it. Read the array elements from standard input. Print out the sorted array, and don’t forget to free the memory. Debug your program using Eclipse C/C++ CDT.
Problem: Write a C++ program that will implement and test the five functions described below that...
Problem: Write a C++ program that will implement and test the five functions described below that use pointers and dynamic memory allocation. The Functions: You will write the five functions described below. Then you will call them from the main function, to demonstrate their correctness. 1. minimum: takes an int array and the array's size as arguments. It should return the minimum value of the array elements. Do not use square brackets anywhere in the function, not even the parameter...
For this computer assignment, you are to write a C++ program to implement a class for...
For this computer assignment, you are to write a C++ program to implement a class for binary trees. To deal with variety of data types, implement this class as a template. Most of the public member functions of the BinaryTree class call private member functions of the class (with the same name). These private member functions can be implemented as either recursive or non-recursive, but clearly, recursive versions of these functions are preferable because of their short and simple implementations...
For this computer assignment, you are to write a C++ program to implement a class for...
For this computer assignment, you are to write a C++ program to implement a class for binary trees. To deal with variety of data types, implement this class as a template. Most of the public member functions of the BinaryTree class call private member functions of the class (with the same name). These private member functions can be implemented as either recursive or non-recursive, but clearly, recursive versions of these functions are preferable because of their short and simple implementations...
Problem: Write a C/C++ program to implement a function that returns 1 when an integer x...
Problem: Write a C/C++ program to implement a function that returns 1 when an integer x contains an odd number of 1s (in its binary representation) and 0 otherwise. You can consider x as a four byte integer, i.e. w = 32 bits. Constraint: Your solution can use at most 12 arithmetic, bitwise, and logical operations.
Write a program for hotel booking system using C++ Program Requirement 1. You can write any...
Write a program for hotel booking system using C++ Program Requirement 1. You can write any program based on the title assigned. 2. The program must fulfill ALL the requirements below. The requirements listed below are the MINIMUM requirement. Your program may extend beyond the requirements if needed. a) Create at least one (1) base class. b) Create at least two (2) derived classes that inherit from the base class created in 2(a). c) Create at least one (1) object...
I need specific codes for this C program assignment. Thank you! C program question: Write a...
I need specific codes for this C program assignment. Thank you! C program question: Write a small C program connect.c that: 1. Initializes an array id of N elements with the value of the index of the array. 2. Reads from the keyboard or the command line a set of two integer numbers (p and q) until it encounters EOF or CTL - D 3. Given the two numbers, your program should connect them by going through the array and...
For this computer assignment, you are to write and implement an interactive C++ program to find...
For this computer assignment, you are to write and implement an interactive C++ program to find and print all prime numbers, which are less than or equal to a given value of n, using the algorithm known as the Sieve of Eratosthenes. A prime number p is an integer greater than 1 that is divisible only by 1 and p (itself). The algorithm begins by initializing a set container to contain all the integers in the range 2 to n....
Problem Description: In C write a program that assigns random integers between 1 and 20 to...
Problem Description: In C write a program that assigns random integers between 1 and 20 to a 5 x 5 two-dimensional array then displays the array with average of each row in a table format and the total of all elements in the array. Also calculate the total of each diagonal, top left to bottom right and top right to bottom left. Display the largest of the diagonal’s totals. Example of the array: 6          10        3          19        20        1          17       ...
CODE IN C++ PLEASE Write a program to implement the algorithm that you designed in Exercise...
CODE IN C++ PLEASE Write a program to implement the algorithm that you designed in Exercise 19 of Chapter 1. Your program should allow the user to buy as many items as the user desires. Instructions for Exercise 19 of Chapter 1 have been posted below for your convenience. Exercise 19 Jason typically uses the Internet to buy various items. If the total cost of the items ordered, at one time, is $200 or more, then the shipping and handling...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT