[C programming] Write a program that reads twofilenames from standard input, opens the first file and copies
Question:
[C programming] Write a program that reads twofilenames from standard input, opens the first file and copies thecontent to the second file with some processing (outlined below);note that the input file will be opened before the output file.Filenames will be a maximum of 80 characters in length.
Your program must:
- Implement the function FILE* openInputFile(char*filename) that opens the input file and returns its filepointer object. The function should print "Input file can't beopened" if the file opening fails for some reason.
- Implement the function FILE* openOutputFile(char*filename) that opens the output file (for writing) and returnsits file pointer object. The function should print "Outputfile can't be opened" if the file opening fails for somereason.
- If either the input and output files can't be opened,exit.
- Otherwise, output a modified version of the input file suchthat:
- All characters must be converted to lowercase, except
- The first character of the file, and the first character afterone or more whitespaces, must be converted to uppercase.
The example test case assumes that your program is called'student_answer'. It also uses the 'cat' command to display thecontents of the output file after your program has run. You do notneed to know about this command, but if you would like to, tryrunning 'man cat' in a terminal.
Hints:
- Remember you should attempt toopen both the input file and the outputfile before exiting if either fails.
- To test opening of the output file at your terrminal, you mustsupply the name of a file that exists AND that you don't havepermission to change - this can also be achieved by trying tocreate a file in a directory you don't have permission to use.
- Use your function readString() from the previousquestion to read the names of the files from the standardinput.
- Use #include which provides thefollowing functions
- isspace(char c) returns true if c is a whitespacecharacter, false otherwise
- toupper(char c) returns the uppercase characterof a-z otherwise the character itself
- tolower(char c) returns the lowercase characterof A-Z otherwise the character itself
Note: The test cases shown are bashcommands.
***There are tons of hidden test (different case butsame template) for testing the program. Here provide one of thecases. ***
For example:
Test | Input | Result |
---|---|---|
cat sample1.txt && ./student_answer && cat output1.txt | sample1.txtoutput1.txt | greetings eArThLinG @ EARThGreetings Earthling @ Earth |
Data Structures and Algorithm Analysis in Java
ISBN: 978-0132576277
3rd edition
Authors: Mark A. Weiss