Question

In: Computer Science

You cna hand write this if you want, Please code this in C Thank you PROBLEM...

You cna hand write this if you want, Please code 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

Solution code is given below with explanation in comments:

#include <stdio.h>

int main()
{
// Variables to hold strings.
char str1[100];
char str2[100];
char str[200];
  
// Taking input from stdin.
fgets(str1, 100, stdin);
fgets(str2, 100, stdin);
  
int i=0,j;
  
// To copy the first string into the str.
// We are making use of '\0' as every string ends by this character.
// Loop will continue until we encounter the null character '\0'.
// Also we will ignore the next line character '\n'.
for(j=0; str1[j]!='\0'; j++) {
if(str1[j]!='\n') {
// For converting to upper case or lower case we are making use
// of ASCII values of the characters as characters are also treated
// as numbers by the language.
// ASCII code for A to Z is 65 to 90.
// ASCII code for a to z is 97 to 122.
// There is difference of 32 in the upper and lower case values of
// each character so just using it for conversion.
if(str1[j] >= 'a' && str1[j] <= 'z')
str[i] = str1[j]-32;
else if(str1[j] >= 'A' && str1[j] <= 'Z')
str[i] = str1[j]+32;
else
str[i] = str1[j];
i++;
}
}
  
// Second loop keeping the i as it is from the previous loop.
// Everything is similar to the above loop.
for(j=0; str2[j]!='\0'; j++) {
if(str2[j]!='\n') {
if(str2[j] >= 'a' && str2[j] <= 'z')
str[i] = str2[j]-32;
else if(str2[j] >= 'A' && str2[j] <= 'Z')
str[i] = str2[j]+32;
else
str[i] = str2[j];
i++;
}
}
  
// Ending the string by the null character.
str[i] = '\0';
  
// Printing the resulted string.
printf("%s", str);
  
return 0;
}

Screenshots:


Related Solutions

Please write code in C, thank you. Write a program that reads a list of integers,...
Please write code in C, thank you. Write a program that reads a list of integers, and outputs whether the list contains all even numbers, odd numbers, or neither. The input begins with an integer indicating the number of integers that follow. Assume that the list will always contain less than 20 integers. Ex: If the input is: 5 2 4 6 8 10 the output is: all even Ex: If the input is: 5 1 3 5 7 9...
Please write code for C language Problem: Write a couple of functions to process arrays. Note...
Please write code for C language Problem: Write a couple of functions to process arrays. Note that from the description of the function you have to identify what would be the return type and what would be part of the parameter. display(): The function takes an int array and it’s size and prints the data in the array. sumArray(): It takes an int array and size, and returns the sum of the elements of the array. findMax(): It takes an...
Hello. If you’re going to hand write the solution, please do so legibly. Thank you. Determine...
Hello. If you’re going to hand write the solution, please do so legibly. Thank you. Determine the amount of sales units that would be necessary under break-even sales under present and proposed conditions. Johnson & Sons Company, operating at full capacity, sold 101,250 units at a price of $129 per unit during the current year. Its income statement for the current year is as follows: Sales $13,061,250 Cost of goods sold 6,450,000 Gross profit $6,611,250 Expenses: Selling expenses $3,225,000 Administrative...
Please use C programming to write the code to solve the following problem. Also, please use...
Please use C programming to write the code to solve the following problem. Also, please use the instructions, functions, syntax and any other required part of the problem. Thanks in advance. Use these functions below especially: void inputStringFromUser(char *prompt, char *s, int arraySize); void songNameDuplicate(char *songName); void songNameFound(char *songName); void songNameNotFound(char *songName); void songNameDeleted(char *songName); void artistFound(char *artist); void artistNotFound(char *artist); void printMusicLibraryEmpty(void); void printMusicLibraryTitle(void); const int MAX_LENGTH = 1024; You will write a program that maintains information about your...
Please solve questions in C++ ASAP!! thank you (a) Write a function in C++ called readNumbers()...
Please solve questions in C++ ASAP!! thank you (a) Write a function in C++ called readNumbers() to read data into an array from a file. Function should have the following parameters: (1) a reference to an ifstream object (2) the number of rows in the file (3) a pointer to an array of integers The function returns the number of values read into the array. It stops reading if it encounters a negative number or if the number of rows...
Please write this code in C++, also if you could please bold the names of the...
Please write this code in C++, also if you could please bold the names of the input files and provide comments for each choice. For this part, the program gives the user 4 choices for encrypting (or decrypting) the first character of a file. Non-lowercase characters are simply echoed. The encryption is only performed on lowercase characters. If c is char variable, then islower(c) will return true if c contains an lowercase character, false otherwise To read a single character...
In C++ Please comment in all-new lines of code, thank you DO NOT USE ANSWERS THAT...
In C++ Please comment in all-new lines of code, thank you DO NOT USE ANSWERS THAT ALREADY BEEN POSTED, please use code from the assignment Copy-paste will be reported Write a program to compare those two searching algorithms and also compare two sorting algorithms. You need to modify those codes in the book/slides to have some counters to count the number of comparisons and number of swaps. In the main function, you should have an ordered array of 120 integers...
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...
PLEASE DO IN C++ AND USE REPL TO WRITE CODE The following problem statement is based...
PLEASE DO IN C++ AND USE REPL TO WRITE CODE The following problem statement is based on a problem in the C++ text by Friedman & Koffman: The results of a survey of the households in your township are available for public scrutiny. Each record (struct-type entity) contains input data for one household, including a four-digit integer identification number the annual income for the household the number of household members. Assuming that no more than 25 households were surveyed, write...
Why is it important for a company to have contingency plans. Please don't hand write. Thank...
Why is it important for a company to have contingency plans. Please don't hand write. Thank you.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT