Read A Line with 8 bytes of data from a file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • neeru29
    New Member
    • Feb 2009
    • 21

    Read A Line with 8 bytes of data from a file

    Can anyone let know how to read a line with maximum of 8 bytes from a line in a file.

    Let say line has 10248 bytes in one single line and same repeats for remaining lines in the file.

    I need to read the first 8 bytes of a line and go on read the last 2 bytes of the line and repeat the till end of file.

    Regards,
    Neeru
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Read a byte at a time into a buffer until you reach 8 or a \n.

    If the \n is there, the two characters before it are the last 2 bytes of the record.

    If the \n is not there, repeat the loop.

    The first 8 bytes you read and the first read after a \n are the 8 lead bytes in the line.

    Comment

    • donbock
      Recognized Expert Top Contributor
      • Mar 2008
      • 2427

      #3
      You say you're reading bytes (suggesting binary file) but you also talk about a file formatted into lines (suggesting text file). What kind of file are you reading? What separates one line from another?

      Comment

      • neeru29
        New Member
        • Feb 2009
        • 21

        #4
        it is text file, separated by the new line character

        Comment

        Working...