The reverse program shown in the slides of chapter 13-1 (also present in the book) reads from a file/command line using system calls and outputs the lines in reverse order on the terminal. The last line is swapped with the first line , the second last is swaped with the second line and so on. It also has a -c option to run with. When used with -c option it reverse the characters of each line as well. For example,
Lets say below are the file contents of your file.
This is line 1
This is line 2
This is line 3
This is line 4
This is line 5
When executed without the -c option the output on terminal would be as follows:
This is line 5
This is line 4
This is line 3
This is line 2
This is line 1
(The order of lines are reversed, fifth line then fourth line then third and so on.) When you run the program with -c option the output would be as follows
After reversing the order of lines, the characters of each line are also reversed. Your homework should you choose to accept it (Of course you have too :P) is to implement this and also implement a -r option. Everything would work the same until the user uses -r option instead of -c. When -c option is used then you would not swap each character of a line rather you would reverse each word. So when used the -r the output would be as follows:
The words are swapped/reversed in each line (last word then second last then third last and so on).
You can assume the following things:
The user will only use file option.
The file will only contain letters, numbers and spaces.