Re: file parsing

Discussion in 'C++' started by Pete, Aug 6, 2003.

  1. Pete

    Pete Guest

    Please excuse my ignorance.....but what does it mean to parse a file?

    "Vladimir Ralev" <> wrote in message
    news:...
    > Hello!
    >
    > I need to parse a file that contains few datasets separated by an
    > empty line, like that:
    > /*----start of file to be parsed-----*/
    > 3 4 5
    > 2 3 6
    > 4 6 8
    > 5 7 9
    >
    > 7 4 2
    > 7 4 3
    > 5 5 5
    > 8 3 1
    > 3 4 1
    >
    > 4 66 6
    > 3 466 4
    > 1 11 77864
    > /*------------ END OF FILE ---------*/
    >
    > Those are ints separated by intervals, three per line.
    > You see here three datasets - the first is the first four lines, the
    > empty line then and then the 5 lines for the second set...and so on.
    >
    > How do I detect an empty line so I could decide where the next set
    > begins using C++ file IO functions?
    >
    > I tryied to:
    > ifstream infile("file");
    > infile>>intvar, but when I check for "\n" i am already skewed coz I
    > wasted walked the iterator forward too much.
    >
    > Thank you!
     
    Pete, Aug 6, 2003
    #1
    1. Advertisements

  2. "Pete" <> wrote...
    > Please excuse my ignorance.....but what does it mean to parse a file?


    Generally, as my understanding of it goes, parsing is separating
    some collection (or stream) into individual items (often called
    "tokens") and then interpreting each token depending on conditions
    set forth in the algorithm. For example, parsing a C++ source file
    would include figuring out the sequence of tokens (done at the
    preprocessing step) and then making sense out of those tokens. It
    is done by the compiler, it is done by many text editors nowadays
    (those who colour the tokens differently when displaying the code,
    so called "syntax highlighting"), it is done by separate syntax
    and logical error checkers (PCLint or something like that)...

    In the OP's case parsing is reading the individual numbers and the
    empty lines, storing the numbers somewhere and interpreting the
    empty lines as special separators.

    Victor
     
    Victor Bazarov, Aug 6, 2003
    #2
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. GIMME
    Replies:
    2
    Views:
    1,130
    GIMME
    Feb 11, 2004
  2. .Net Sports
    Replies:
    11
    Views:
    1,777
    .Net Sports
    Jan 17, 2006
  3. Naren
    Replies:
    0
    Views:
    775
    Naren
    May 11, 2004
  4. Christopher Diggins
    Replies:
    0
    Views:
    759
    Christopher Diggins
    Jul 9, 2007
  5. Christopher Diggins
    Replies:
    0
    Views:
    576
    Christopher Diggins
    Jul 9, 2007
  6. seafoid
    Replies:
    2
    Views:
    452
    seafoid
    Dec 18, 2009
  7. John Levine
    Replies:
    0
    Views:
    934
    John Levine
    Feb 2, 2012
  8. Replies:
    6
    Views:
    474
    cartercc
    Jun 17, 2008
Loading...