Video Coming Soon...
51: head and tail
WARNING: This is from the Go course but I'm rewriting the code and the description to fit C. If you want to attempt it go ahead. The challenge is the same, just no examples yet.
The tail command prints out the tail of a file or input stream, which becomes insanely useful when you have to manage your own systems. You'll be "tailing that log" all the time, which means using tail to get the last 20 or so lines of a log file.
The head command rarely shows up in my daily Linux usage, but it's actually the easier of the two to implement which is why I have you start with head.To implement head you count how many lines, then stop when you read the required number. With tail you have to "eat" lines until you reach the end, then print the last 20.
The Challenge
You don't have to be efficient with your implementation, but try to get as many command line options working as possible. If you want to go for extra points you'll try to find a way to make tail not use too much memory. My implementation collects the entire contents of a file into memory, then prints only the tail. See if you can do better.
The documentation is here:
Register for From Impostor to Programmer
Register today for the course and get the all currently available videos and lessons, plus all future modules for no extra charge.