Extracting the first column from a file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chandra85
    New Member
    • Sep 2007
    • 1

    Extracting the first column from a file

    i need to get first column alone from a text file. i think it can b done with fread. so pls say how to do it.
    Last edited by chandra85; Sep 25 '07, 04:57 AM. Reason: spelling mistake
  • gpraghuram
    Recognized Expert Top Contributor
    • Mar 2007
    • 1275

    #2
    Originally posted by chandra85
    i need to get first column alone from a text file. i think it can b done with fread. so pls say how to do it.
    Is the file delimited by a space?
    If yes then use fgets to read the line and use sscanf to get the first token.

    Raghuram

    Comment

    • sicarie
      Recognized Expert Specialist
      • Nov 2006
      • 4677

      #3
      chandra85-

      Please do not double-post. I have removed your other post on the subject.

      Comment

      • forse
        New Member
        • Sep 2007
        • 7

        #4
        Hi,

        If your columns have a field separator, then you can read the file content character by character, until you reach your field separator.

        Here is a Tutorial on reading and writing files in C++

        Comment

        Working...