Advertisement

scanf error just made my day

Started by December 21, 2000 10:46 AM
4 comments, last by Galileo430 24 years ago
Ok, I have read data from a text file and place it in char Line[100]. Line looks like this "set resx 800" I then use the following sscanf line to break it up into it''s words.
  
int Value;

if (sscanf(Line, "%s%s%d", Type, Command, &Value) == EOF)
{
....
  
Now, if Value can''t take 800 from Line then I figured I would return a string by makeing %d, %s and removing the &. However all I get back in that case is high ASCII. I am puzzled.. Anyone see a obvious error I missed in these last 8 hours?
------------------------------------------------------------I wrote the best video game ever, then I woke up...
ISTR sscanf returns the number of items successfully read. So you probably want:

  if(sscanf(Line, "%s%s%d", Type, Command, &Value) == 3)  

Advertisement
I think you are basically on the right track.

One thing, sscanf returns the number of successfully converted
arguments (so, you should test for != 3 would mean all args weren''t converted, not for EOF [which only applies to scanf]).

Enjoy


Nope, still get 0x817a379c or high ASCII..
------------------------------------------------------------I wrote the best video game ever, then I woke up...
AH! Found the bug.

For some reason sscanf is not reading the Line..
------------------------------------------------------------I wrote the best video game ever, then I woke up...
Got it!
------------------------------------------------------------I wrote the best video game ever, then I woke up...

This topic is closed to new replies.

Advertisement