Question
Prepare a text file with several lines of text. Write a C program that reads the text file name from the user via the keyboard.
Prepare a text file with several lines of text. Write a C program that reads the text file name from the user via the keyboard. The C program should also read a file name that is used to store the output. Open the given text file and read lines stored in that text file. For each line, change the lowercase letters (a to z) to upper case letters (A to Z) and change the uppercase letters to lowercase letters. Write changed lines to the given output file.
Hint: (i) You can assume the maximal length of each line in the file is 1024. (ii) When you get a file name str from the user, you can use fopen(str, r) to open that file. (iii) You can use whether the return value of fgets() is NULL to juedge whether we meet the end-of-file (EOF) mark. For example, fgets(str, 1024, inFile) == NULL when the file stream inFile meets the EOF mark. (iv) The string you get from fgets() already have a at the end of the string. Therefore, when you print the string to the file, you do not need to add a after it.
The following is the sample content of a text file input.txt.
The following is the sample run of the program (The blue font is input by the user).
After the program finishes, the content of output.txt file is
(i) Please upload the source code file as the attachment. (ii) Please upload the input file and output file of your sample run as the attachments.
This is the first line. Next line is here. Finish the input by a enter key. Please enter the input file name: input.txt Please enter the output file name: output.txt Done! THIS IS THE FIRST LINE. NEXT LINE IS HERE. FINISH THE INPUT BY A ENTER KEYStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started