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. Advertisements

  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. Advertisements

  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. 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. jacob navia

    sscanf problem

    jacob navia, Jul 9, 2004, in forum: C Programming
    Replies:
    6
    Views:
    442
    jacob navia
    Jul 10, 2004
  2. baumann@pan

    problem with sscanf.

    baumann@pan, Jun 2, 2005, in forum: C Programming
    Replies:
    4
    Views:
    513
    baumann@pan
    Jun 3, 2005
  3. Replies:
    4
    Views:
    395
    CBFalconer
    May 2, 2006
  4. Alex Mathieu

    Problem using sscanf...

    Alex Mathieu, Mar 21, 2007, in forum: C++
    Replies:
    5
    Views:
    577
    Adrian Hawryluk
    Mar 22, 2007
  5. Timo

    Simple sscanf parsing problem

    Timo, Jun 28, 2008, in forum: C Programming
    Replies:
    4
    Views:
    577
    CBFalconer
    Jun 28, 2008
  6. dorayme
    Replies:
    1
    Views:
    786
    richard
    Jan 21, 2011
  7. Beauregard T. Shagnasty

    Re: A Weird Appearance for a Weird Site

    Beauregard T. Shagnasty, Jan 21, 2011, in forum: HTML
    Replies:
    1
    Views:
    586
    Captain Paralytic
    Jan 21, 2011
  8. will
    Replies:
    6
    Views:
    636
    Phrogz
    Dec 27, 2006
Loading...