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 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 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...
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...
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...
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...
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.
please write the code in C not c++, and not to use Atoi or parseint to...
please write the code in C not c++, and not to use Atoi or parseint to parse the string, Thank you. #include <stdio.h> #include <stdbool.h> /* * The isinteger() function examines the string given as its first * argument, and returns true if and only if the string represents a * well-formed integer. A well-formed integer consists only of an * optional leading - followed by one or more decimal digits. * Returns true if the given string represents an...
Please answer with code for C language Problem: Counting Numbers Write a program that keeps taking...
Please answer with code for C language Problem: Counting Numbers Write a program that keeps taking integers until the user enters -100. In the end, the program should display the count of positive, negative (excluding that -100) and zeros entered. Sample Input/Output 1: Input the number: 0 2 3 -9 -6 -4 -100 Number of positive numbers: 2 Number of Negative numbers: 3 Number of Zero: 1
Code in C++ please You are going to write a program for Computer test which will...
Code in C++ please You are going to write a program for Computer test which will read 10 multiple choice questions from a file, order them randomly and provide the test to the user. When the user done the program must give the user his final score
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT