Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Weird problem: sscanf

Reply
Thread Tools

Weird problem: sscanf

 
 
PX
Guest
Posts: n/a
 
      02-18-2004
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!
 
Reply With Quote
 
 
 
 
nrk
Guest
Posts: n/a
 
      02-18-2004
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
 
Reply With Quote
 
 
 
 
Anupam
Guest
Posts: n/a
 
      02-18-2004
(PX) wrote in message news:<. com>...
> 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
 
Reply With Quote
 
Mark McIntyre
Guest
Posts: n/a
 
      02-23-2004
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 =---
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: A Weird Appearance for a Weird Site Beauregard T. Shagnasty HTML 1 01-21-2011 04:17 PM
Re: A Weird Appearance for a Weird Site richard HTML 0 01-21-2011 07:10 AM
Re: A Weird Appearance for a Weird Site dorayme HTML 1 01-21-2011 06:51 AM
Re: A Weird Appearance for a Weird Site richard HTML 0 01-21-2011 06:46 AM
Re: sscanf(): weird behavior? Chris Torek C Programming 0 06-26-2003 06:11 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57