Question: Linux has a command called tail, which returns the last few lines of the standard input. You are to write a program (called mytail) that
Linux has a command called tail, which returns the last few lines of the standard input. You are to write a program (called mytail) that behaves similarly. In particular, if the program is called with no command arguments; it returns the last 10 lines of its input. Otherwise, it must be called with one command argument, as in problem 1. In this case, the program returns the last n lines of its input. Here is an example in action:
You must write (and use) a function named readaline to read each line of input. The function is called like this: char *line = readaline(80); The argument to the readaline function is an integer denoting the maximum number of characters to read. The function calls malloc to allocate space for these characters, and passes this array to fgets. The function fgets will return NULL if it encounters end-of file. In this case, readaline should free the allocated space and return NULL. Otherwise it should return a pointer to the space. Note that fgets adds the newline character ' ' to the array, followed by the '
adminuser@adminuser-VirtualBox /media/sf_Shared $mytail
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
