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

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

  1. 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.
  2. 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.
  3. If either the input and output files can't be opened,exit.
  4. Otherwise, output a modified version of the input file suchthat:
    1. All characters must be converted to lowercase, except
    2. 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:

TestInputResult
cat sample1.txt && ./student_answer && cat output1.txt
sample1.txtoutput1.txt
greetings eArThLinG  @  EARThGreetings Earthling  @  Earth

Step by Step Solution

3.53 Rating (160 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Code Output Solution Consider the following substitution Substitute 20 an... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Electrical Engineering Questions!