Problem with sscanf

Jeff Newberry newberry at nmsu.edu
Wed Feb 6 06:17:09 AEST 1991


>I'm having problem with sscanf. I would like to get items in a string
>delimited by a coma. So I wrote :

>sscanf("1,,3", "%[^,],%[^,],%[^,]", s1, s2, s3);

>I get "1" into s1, "" into s2...
>But what goes into s3 is *not* "3". Of course, I could write
>my own function, but I would like to know if something is wrong
>with this.


>From my experience, if "%[^,]" sees a ',' before it sees anything
else, it will stop trying to read and return the number of arguments
that have successfully been read.  Apparently, scanf considers it an
error if it is told to read everything but ',' but then can't read
anything. So, my suggestion is to print out what sscanf is returning.
My bet is that sscanf is returning 1.


Jeff Newberry
Computing Research Lab
newberry%nmsu.edu



More information about the Comp.lang.c mailing list