marty@cernvax.cern.ch (hugues marty) (02/05/91)
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. Tnx -- e+ ----> :-) <---- e- e-mail : Les Chercheurs de Bosons Unifies marty@cernvax.cern.ch
newberry@nmsu.edu (Jeff Newberry) (02/06/91)
>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