Question

In: Computer Science

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 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

Note: here each line of code is explained in the comment section, but if you any error or issue or dont understand the code feel free to ask me or post the issue.

(Remove that two scanf() comment code after fgets(), used only for checking the code).

myString.c

#include<stdio.h>
#define MAX_LIMIT 100

int main(){
    char str1[MAX_LIMIT], str2[MAX_LIMIT], res[2*MAX_LIMIT];
    int i = 0, k = 0;
    
    fgets(str1, MAX_LIMIT, stdin);
    fgets(str2, MAX_LIMIT, stdin);
    
  //  scanf("%[^\n]%*c",str1);
  //  scanf("%[^\n]%*c",str2);
    
    // for str1
    for(i=0; str1[i]!='\0'; i++){
        
        // store str1[i] to char ch
        char ch = str1[i];
        
        // if ch is between 'A' to 'Z'
        if(ch >= 'A' && ch <= 'Z')
            str1[i] += 32;
            
        // if ch is between 'a' to 'z'
        else if(ch >= 'a' && ch <= 'z')
             str1[i] -= 32;
             
        // check for next line ch if found continue loop     
        else if(ch == '\n')
             continue;     
             
        // store to res array
        res[k++] = str1[i];
         
    }
    
    // for str2 
    for(i=0; str2[i]!='\0'; i++){
        char ch = str2[i];
        
        // if ch is between 'A' to 'Z'
        if(ch >= 'A' && ch <= 'Z')
            str2[i] += 32;
            
        // if ch is between 'a' to 'z'
        else if(ch >= 'a' && ch <= 'z')
             str2[i] -= 32;
             
        // check for next line ch if found continue loop        
        else if(ch == '\n')
             continue;      
             
        // store to res array
        res[k++] = str2[i];
    }
    
    // store last char with null to print string before NULL value
    res[k] = '\0';
    
    // print res string
    printf("%s",res);
    
    return 0;
}

Related Solutions

For this computer assignment, you are to write a C++ program to implement a class for...
For this computer assignment, you are to write a C++ program to implement a class for binary trees. To deal with variety of data types, implement this class as a template. Most of the public member functions of the BinaryTree class call private member functions of the class (with the same name). These private member functions can be implemented as either recursive or non-recursive, but clearly, recursive versions of these functions are preferable because of their short and simple implementations...
Problem: Write a C/C++ program to implement a function that returns 1 when an integer x...
Problem: Write a C/C++ program to implement a function that returns 1 when an integer x contains an odd number of 1s (in its binary representation) and 0 otherwise. You can consider x as a four byte integer, i.e. w = 32 bits. Constraint: Your solution can use at most 12 arithmetic, bitwise, and logical operations.
Write a program for hotel booking system using C++ Program Requirement 1. You can write any...
Write a program for hotel booking system using C++ Program Requirement 1. You can write any program based on the title assigned. 2. The program must fulfill ALL the requirements below. The requirements listed below are the MINIMUM requirement. Your program may extend beyond the requirements if needed. a) Create at least one (1) base class. b) Create at least two (2) derived classes that inherit from the base class created in 2(a). c) Create at least one (1) object...
I need specific codes for this C program assignment. Thank you! C program question: Write a...
I need specific codes for this C program assignment. Thank you! C program question: Write a small C program connect.c that: 1. Initializes an array id of N elements with the value of the index of the array. 2. Reads from the keyboard or the command line a set of two integer numbers (p and q) until it encounters EOF or CTL - D 3. Given the two numbers, your program should connect them by going through the array and...
Problem Description: In C write a program that assigns random integers between 1 and 20 to...
Problem Description: In C write a program that assigns random integers between 1 and 20 to a 5 x 5 two-dimensional array then displays the array with average of each row in a table format and the total of all elements in the array. Also calculate the total of each diagonal, top left to bottom right and top right to bottom left. Display the largest of the diagonal’s totals. Example of the array: 6          10        3          19        20        1          17       ...
Write a program to implement and analyzing the Bubble Sort. a. Write a C++ function for...
Write a program to implement and analyzing the Bubble Sort. a. Write a C++ function for Bubble Sort b. Use a dynamic array of integers in a variable size of n. c. Display the following information: 1) Total counts of comparisons 2) Total counts of shifts / moves / swaps, whichever applies d. Write a main() function to test a best, and an average cases in terms of time efficiency i. Fill out the array with random numbers for an...
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...
write C program to implement the priority queue with the operation insert
write C program to implement the priority queue with the operation insert
Problem description Write a C++ program that prompts the user to enter two non-negative integers, firstNum...
Problem description Write a C++ program that prompts the user to enter two non-negative integers, firstNum and secondNum. The program then prints all palindromic primes (Links to an external site.) between firstNum and secondNum, inclusive. A palindromic number is a number whose digits are the same forward or backward (e.g., 12321). A palindromic prime is a prime number that is also a palindromic number (e.g., 101). You must implement and use the following functions as prototyped below: /// --------------------------------------------------------------- ///...
Write the code in C++. Write a program to implement Employee Directory. The main purpose of...
Write the code in C++. Write a program to implement Employee Directory. The main purpose of the class is to get the data, store it into a file, perform some operations and display data. For the purpose mentioned above, you should write a template class Directory for storing the data empID(template), empFirstName(string), empLastName(string), empContactNumber(string) and empAddress(string) of each Employee in a file EmployeeDirectory.txt. 1. Write a function Add to write the above mentioned contact details of the employee into EmployeeDirectory.txt....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT