Write change: Given two strings, change copies lines from the standard input to the standard output replacing all occurrences of the first string by the second. change is invoked by the command
change from toand prints the lines in the standard input changing all occurrences of the string from to the string to. The strings from and to do not have to be the same length. For example, if the file foo contains
Now is the time for all good men to come the aid of their country.the command
change the first <fooprints the following to standard out:
Now is first time for all good men to come first aid of firstir country.In addition to printing the transformed text on standard out, change should print the number of substitutions performed and the number of characters by which the input file grew or shrunk as diagnostic information to standard error. For the above input, the standard error output should be as follows:
3 substitutions +6 charactersThe to string is optional; if it is omitted, the effect is to delete occurrences of the from string. Thus, the command
change the <fooprints
Now_is__time for_all_good_men to_come__aid_of_ir_country.where underscores denote spaces. Note the two spaces between is and time in the first line and between come and aid in the last line.
The standard error output should be:
3 substitutions -9 charactersThere is a convention that lines of text are no longer than 80 characters. Your program must behave reasonably with longer lines, that is it must not crash. However, it may ignore characters in the 81st column and beyond. Also, make sure your program does something reasonable with the boundary cases, e.g., a null from string (change ""), empty input, etc. Briefly explain how you deal with boundary cases in your readme file. Note that the line length of your output may grow beyond 80 characters as a result of substitutions. Do not truncate it.
An executable solution is available at /u/cs217/Assignment1/change. This implementation is 59 lines of C and uses 7 different routines from the Standard C library.
/u/cs217/bin/submit 1 readme makefile change.cYou may use other computing facilities to develop your program, but the submitted version must compile with lcc -A and execute correctly on Arizona. To encourage good coding practices, you will lose points for any warning messages generated by lcc during the compilation of your program.
Due: submitted by 11:59pm, Mon. 2/12/2001.