Question

In: Computer Science

Program this using C please The program will read from standard input two things - a...

Program this using C please 

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

Given below is the code for the question. Please do rate the answer if it helped. Thank you.


#include <stdio.h>
int main(){
   char str1[100], str2[100], str3[200];
   int i = 0, j = 0;
   char c;
  
   printf("Enter string1 \n");
   fgets(str1, 100, stdin);
   printf("Enter string2 \n");
   fgets(str2, 100, stdin);
  
   /*first copy first string onto str3*/
   for(i = 0; str1[i] != '\n' && str1[i] != '\0' ; i++)
   {
       c = str1[i];
       if(c >= 'a' && c <= 'z')
           c = c - 'a' + 'A'; //convert to upper case
       else if(c >= 'A' && c <= 'Z')
           c = c - 'A' + 'a'; //convert to lower case
       str3[i] = c;
   }
  
   /*now concatenate str2 to str3*/
  
   for(j = 0; str2[j] != '\n' && str2[j] != '\0'; i++, j++)
   {
       c = str2[j];
       if(c >= 'a' && c <= 'z')
           c = c - 'a' + 'A'; //convert to upper case
       else if(c >= 'A' && c <= 'Z')
           c = c - 'A' + 'a'; //conver to lower case
       str3[i] = c;
   }
  
   str3[i] = '\0';
  
   printf("%s\n", str3);
   return 0;
}


Related Solutions

Write a program that takes three sets ’A’, ’B’, ’C’ as input read from the file...
Write a program that takes three sets ’A’, ’B’, ’C’ as input read from the file prog2 input.txt. The first line of the file corresponds to the set ’A’, the second line is the set ’B’, and the third line is the set ’C’. Every element of each set is a character, and the characters are separated by space. Implement algorithms for the following operations on the sets. Each of these algorithms must be in separate methods or subroutines. The...
Write a program that takes two sets ’A’ and ’B’ as input read from the file...
Write a program that takes two sets ’A’ and ’B’ as input read from the file prog1 input.txt. The first line of the file corresponds to the set ’A’ and the second line is the set ’B’. Every element of each set is a character, and the characters are separated by space. Implement algorithms for the following operations on the sets. Each of these algorithms must be in separate methods or subroutines. The output should be written in the file...
Write a program read in data from the standard input stream (cin) representing temperature in Fahrenheit....
Write a program read in data from the standard input stream (cin) representing temperature in Fahrenheit. The program will then convert the values into Kelvin (using 5/9 (Fº-32) to convert to Celsius and a difference of 273.15 between Celsius and Kelvin) and print out the new total value. Convert temperature in Fahrenheit to Kelvin : Enter temperature in Fahrenheit: 80.33 The temperature in Kelvin is: 300 Write a second program which then does the reverse conversion (using a difference of...
In C++, write a program that accepts a text file of ASCII words from standard input...
In C++, write a program that accepts a text file of ASCII words from standard input and store them and the amount of times the word appears in the file in a hash table using external chaining. Then print the words and their counts sorted based on alphabetical order and print them again in decreasing numerical order based on the amount of times the word appears in the file. Space, tab, and new line all count as space characters. The...
C++ Read first a user's given name followed by the user's age from standard input. Then...
C++ Read first a user's given name followed by the user's age from standard input. Then use an ofstream object named outdata (which you must declare) to write this information separated by a space into a file called outdata. Assume that this is the extent of the output that this program will do. Declare any variables that you need.
Design and implement a C++ program read in a whole line of characters as the input...
Design and implement a C++ program read in a whole line of characters as the input string; count and display how many times how frequently (among the letters) each (case insensitive) letter appears in the above mentioned input string; Sample program execution: An example of executing such a program is shown below. Note that the user input is in italic font. Please enter a line of characters: This is a really long line of characters! There are 41 characters in...
Write a short C++ program that takes all the lines input to standard input and writes...
Write a short C++ program that takes all the lines input to standard input and writes them to standard output in reverse order. That is, each line is output in the correct order, but the ordering of the lines is reversed. Please use vector datatype standaard library #include <vector> Thanks
C++ code please: Write a program that first gets a list of integers from input. The...
C++ code please: Write a program that first gets a list of integers from input. The input begins with an integer indicating the number of integers that follow. Then, get the last value from the input, which indicates how much to multiply the array by. Finally, print out the entire array with each element multiplied by the last input. Assume that the list will always contain less than 20 integers. Ex: If the input is 4 4 8 -4 12...
Write a C program, called reverse, using standard I/O functions, to take a file as input...
Write a C program, called reverse, using standard I/O functions, to take a file as input then copies it to another file in reverse order. That is, the last byte becomes the first, the byte just before the last one becomes the second, etc. The program call should look like: reverse fileIn fileOut
Write a program in C, that uses standard input and output to ask the user to...
Write a program in C, that uses standard input and output to ask the user to enter a sentence of up to 50 characters, the ask the user for a number between 1 & 10. Count the number of characters in the sentence and multiple the number of characters by the input number and print out the answer. Code so far: char sentence[50]; int count = 0; int c; printf("\nEnter a sentence: "); fgets(sentence, 50, stdin); sscanf(sentence, %s;    for(c=0;...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT