Increment File Pointer In A Text File

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aditigupta
    New Member
    • Jul 2007
    • 6

    Increment File Pointer In A Text File

    HI...
    Actually i m trying to move my file pointer from one line to another line but m not able to do so by using fseek because i dont know the offset.......

    so is there anybody who can help........

    thanks
  • Silent1Mezzo
    New Member
    • Feb 2007
    • 208

    #2
    Originally posted by aditigupta
    HI...
    Actually i m trying to move my file pointer from one line to another line but m not able to do so by using fseek because i dont know the offset.......

    so is there anybody who can help........

    thanks
    Are you just going to the next line?

    Comment

    • aditigupta
      New Member
      • Jul 2007
      • 6

      #3
      no i want to move to any line from the present file pointer position....... .. is there any way out.......

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        Do you have a flat file? That is, are all of the records the sam length??

        If so, you can calculate an offset from the beginning of the file and seek to that location.

        If not, you will have to start at the beginning of the file and read it character by character counting the end of record characters (probably \n). As you find an end of record character, the next record starts at the next byte. Seek to that byte.

        I urgently recommend a flat file for this type of random hopping about. Further, if you have to change the data and the records are different lengths, then you simply can't do it without corrupting the file.

        Comment

        Working...