a. Write a C program to open and close a file given its name. Your program must
check whether or not the file exists.

b. Add a function for reading an opened file into an array of characters. You may
assume the array is large enough to hold an entire file (e.g. 100,000 characters).

c. Add a function for saving the text stored in an array to a file. Your program must
check whether or not the output file already exists, and if it does, your program
must ask the user whether he/she wishes to overwrite the file.

d. Extend your program to count the number of words and characters in the text file.
An algorithm for counting words is given in the textbook.

e. Add a function for inserting a string into the array. Insertion is done by providing a
start position and a string.

f. Add a function for deleting strings from the array. Deletion is done by providing a
start position and the length of the string to be deleted.

g. Add a function that searches the text for a pattern. Show all occurrences of a
string.

h. Add a function to replace all occurrences of a string with a new string. Note that
this operation is a combination of search, delete, and insert operations.

Once all the functions have been implemented, you should design a menu that is used for
informing users about selection. “Pico” text editor in Linux is a good example.

The purpose of homework is to help you think about the problem domain that the class is trying to cover. Asking us to do your homework for you is cheating... :-( Try to solve the problems yourself first, and then we will try to help you understand and fix your code.

This article has been dead for over six months. Start a new discussion instead.