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...
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.
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...
Create a C++ program that calculates an unbiased standard deviation of 5 input numbers. Please Submit:...
Create a C++ program that calculates an unbiased standard deviation of 5 input numbers. Please Submit: 1. A flowchart of your program. (3 points) 2. Your C++ program with a heading comment, also appropriate spacing and indentation in the program body. 3. Copy of a screenshot after your program is executed. (Section 2 and3: 7 points) /* ELEN 1301 Programming Assignment #8. Name : Your name. Student ID : Your student ID #. Due date : Purpose of the program...
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
IN C++ PLEASE Requirements Write a program that takes in user input of two integer numbers...
IN C++ PLEASE Requirements Write a program that takes in user input of two integer numbers for height and width and uses a nested for loop to make a rectangle out of asterixes. The creation of the rectangle (i.e. the nested for loop) should occur in a void function that takes in 2 parameters, one for height and one for width. Make sure your couts match the sample output (copy and paste from those couts so you don't make a...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT