reading data and outputting data on screen if more or previous is entered

This is a discussion on reading data and outputting data on screen if more or previous is entered within the C Programming forums, part of the General Programming Boards category; how would i go about writing a program that takes a txt file and printing the first 20 lines if ...

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    44
    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.
    Last edited by loso44x; 10-22-2005 at 02:13 AM.

  2. #2
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    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().

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. question regarding outputting data to adobe flash
    By hoax464 in forum C++ Programming
    Replies: 1
    Last Post: 07-21-2008, 02:08 PM
  2. Outputting data to ports
    By FwyWice in forum C++ Programming
    Replies: 1
    Last Post: 11-27-2002, 08:42 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21