reading variable length lines from a file

Discussion in 'Mac Programming' started by farmerdoug, Feb 26, 2011.

  1. farmerdoug macrumors 6502a

    Joined:
    Sep 16, 2008
    #1
    Lines in my files are not of the same length. However the date is always first.
    For a while

    fscanf(file, "%s %s \n", date, therest);

    worked in that everything past the date was dumped into therest. I don't know what I did but it doesn't work anymore.

    How do I read the first element of every line, independent of what follows?
     
  2. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #2
    fgets() to read the line into a buffer.
    Check for EOF, errors, incomplete lines, etc.
    sscanf() to parse the data from the line buffer.
     
  3. farmerdoug thread starter macrumors 6502a

    Joined:
    Sep 16, 2008

Share This Page