Here is a solution sketch.
To make this usable as a future assignment, I have removed
all semblence of comments, error checks, and have not done a separate
However, you can see the basic algorithms at work.
Comments: Command #2 will work as long as you have correctly handled
the case of having no filename. The processing of the < will be
handled by the operating system, and not by your program.
The last two commands should generate errors. The others are