I have to read from terminal some text using only system calls(for Linux) in C and then output the last 6 lines(just like the tail command in linux). How do I do that? If the file is smaller than 6 lines, the whole files should be outputed. The output should be with write.
Sample input:
1
2
344444
44444
555555555555555555555555555555555555
6
7
8
9
100000
11
OUTPUT:
6
7
8
9
100000
11
Using read(), dup() & close() fixed my problem.