sscanf() runtime error

Hello everyone!

I am trying to read the string: Name: Toni, Age: 18, Weight: 80.5

using:
 
sscanf(mystring, "Name: %s%[^,], Age: %d%[^,], Weight: %f, name, &age, &weight");


I can't any of the arguments give me the right answer...

I want to use sscanf(), I mean this is SPECIFICALLY why it is created, I don't wish to use strtok().
You messed up the format. (I assume the " was a typo)
try sscanf(mystring, "Name: %[^,], Age: %d, Weight: %f", name, &age, &weight);
Last edited on
Yes it was a typo but only here...

I think it should be like this
1
2
3
4
char name[10];
int age;
double weight;
sscanf(mystring, "Name: %[^,], Age: %d%[^,], Weight: %f", name, &age, &weight);


Output In both cases is:

Toni 18 8.63788e-308

Boy I am slim!

----

Edit: Ah, ah, sir! For testing I modifed age to be a double, gave me an unexpected input too...
Hope this helps solving the problem.

Last edited on
Topic archived. No new replies allowed.