In: Computer Science
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
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;
}