Advanced Programming Course - Exercise 4

http://www.oocities.org/SiliconValley/Peaks/8778/TAU_advprog.html

To write a program that gets as arguments a number and a name of a text file and prints to standard output the correspondent number of the last lines. I.e. if your program is prog.exe and your text file is aaa.txt then the command:

prog 15 aaa.txt
will print the last 15 lines of the file aaa.txt. Implement this functionality using queue where you will store the last N lines read from the file all the time, i.e. each time you read line you add it to the queue and if you have read already more than N lines then you delete from the queue the oldest line. After read of the all lines you will simply print lines remaining in the queue.

Use the following structs to implement the queue (supposing that each line is not longer than 1024 characters):

typedef struct string_node
{
	char line[1024];
	struct string_node* next;
	struct string_node* prev;
} SNODE;

typedef struct string_queue
{
	SNODE* first;
	SNODE* last;
} SQUEUE;
Notes:
  1. This is not the most efficient way to perform this task, this solution is used for educational purposes.
  2. Such a queue when each insertion follows by getting (deletion) has its own name: "ring".