Weird problem: sscanf

Discussion in 'C Programming' started by PX, Feb 18, 2004.

  1. PX

    PX Guest

    Greetings,

    Say I want to read a file line by line so I used fgets(). And I want
    to parse strings from each line of the file, I used sscanf(). But
    there's a strange problem that each time I run the program, sscanf()
    cannot read in first line of file correctly. It always appends a
    character at the end of last string that's been parsed. I am working
    on HP-UX using cc. Anybody has any clue?

    Thanks a bunch!
     
    PX, Feb 18, 2004
    #1
    1. Advertising

  2. PX

    nrk Guest

    PX wrote:

    > Greetings,
    >
    > Say I want to read a file line by line so I used fgets(). And I want
    > to parse strings from each line of the file, I used sscanf(). But
    > there's a strange problem that each time I run the program, sscanf()
    > cannot read in first line of file correctly. It always appends a
    > character at the end of last string that's been parsed. I am working
    > on HP-UX using cc. Anybody has any clue?
    >
    > Thanks a bunch!


    Post a small, reasonably complete, preferably compilable piece of code
    showing the problem. Without that, it's a bit like reading your fortune
    off tea leaves.

    -nrk.
    --
    Remove devnull for email
     
    nrk, Feb 18, 2004
    #2
    1. Advertising

  3. PX

    Anupam Guest

    (PX) wrote in message news:<>...
    > Greetings,
    >
    > Say I want to read a file line by line so I used fgets(). And I want
    > to parse strings from each line of the file, I used sscanf(). But
    > there's a strange problem that each time I run the program, sscanf()
    > cannot read in first line of file correctly. It always appends a
    > character at the end of last string that's been parsed. I am working
    > on HP-UX using cc. Anybody has any clue?
    >
    > Thanks a bunch!


    Please post the smallest compilable piece of code which exhibits the
    problem. The problem could be that fgets() keeps the newline while
    sscanf() doesnt. It would be quite difficult to comment without
    getting something more solid to digest.
    Regards,
    Anupam
     
    Anupam, Feb 18, 2004
    #3
  4. On 17 Feb 2004 19:02:43 -0800, in comp.lang.c , (PX)
    wrote:

    >Greetings,
    >
    >Say I want to read a file line by line so I used fgets(). And I want
    >to parse strings from each line of the file, I used sscanf(). But
    >there's a strange problem that each time I run the program, sscanf()
    >cannot read in first line of file correctly. It always appends a
    >character at the end of last string that's been parsed. I am working
    >on HP-UX using cc. Anybody has any clue?


    Post a small example of your code. We're not telepathic... by the way,
    whats the "extra character" ? 0x0d or 0x0a by any chance?

    --
    Mark McIntyre
    CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
    CLC readme: <http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html>


    ----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
    http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
    ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
     
    Mark McIntyre, Feb 23, 2004
    #4
    1. Advertising

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. Chris Torek

    Re: sscanf(): weird behavior?

    Chris Torek, Jun 26, 2003, in forum: C Programming
    Replies:
    0
    Views:
    1,442
    Chris Torek
    Jun 26, 2003
  2. dorayme
    Replies:
    1
    Views:
    650
    richard
    Jan 21, 2011
  3. richard
    Replies:
    0
    Views:
    608
    richard
    Jan 21, 2011
  4. richard
    Replies:
    0
    Views:
    634
    richard
    Jan 21, 2011
  5. will
    Replies:
    6
    Views:
    440
    Phrogz
    Dec 27, 2006
Loading...

Share This Page