how would i go about writing a program that takes a txt file and printing the first 20 lines if i pressed m or pritning the previous 20 lines if i press p...is there an easy way to do this. any tips would be greatly appreciated. if you are showing me the pointer way can u plz explain in detail since im a newbie at pointers.
one way to do that is to keep track of the starting file position before reading the file (fgetpos() will do that), read and display 20 lines ( fgets() ) then wait for keyboard entry. If m is pressed, call fgetpos() again, read and display the next 20 lines. If p is pressed, call fsetpos() to reset the file position back to its previous position then read and display the next 20 lines.
the only pointer involved is the FILE* pointer and the object needed by fsetpos() and fgetpos().