Question: Write a program for each of the following exercises in C programming language. If your main() function does more than one task, define the necessary

Write a program for each of the following exercises in C programming language. If your main() function does more than one task, define the necessary functions to take care of those tasks. Files referred to in these exercises are text files. You can assume that file names do not contain whitespaces.

1.Ask user for the name of a text file then print out its contents to the screen.

2.Implement a function int copy(char *infilename, char *outfilename). This function reads the content of a file whose name is infilenameand write that content to another file whose name is outfilename. The function returns 1 if the copy attempt is successful and 0 if it fails.

3.Ask user for the name of an input text file then create an output text file whose content looks the same as the input text file except that it has a line number, starting from 1, at the beginning of each line.

4.Ask user for the name of a text file then count the number of lines(a line is a sequence of characters ending by an newline),and words(a word is a sequence of characters ending by a whitespace)in that file.

5.Extend exercise 2 so that can run the program as:$ ./copy infile outfile

6.Extend exercise 3 so that you can run the program as:$ ./copywithlinenum infile outfile

7.Extend exercise 4 so that you can run the program as:$ ./count file

8.Compare two given text files, printing the first line from each file where they differ. Your program should run as:$ ./compare file1 file2

9.Append the content of file2 to end of file1. Your program should run as:$./append file1 file2

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!