I'm trying to read formatted data with sscanf in this format:
"%d,%d,%d"
for example,
sscanf(buffer, "%d,%d,%d", n1, n2, n3)
and it is critic that there is no white space between every number, because the input comes like this, for example:
109,304,249
194,204,482
etc.
But when I give sscanf an input like:
13, 56, 89
145, 646, 75
it still reads it even though it is not in the specifed format, and should be invalid
Is there is a way to write something such that sscanf will work as I expect it to work?
scanfignores leading whitespace for most conversions, but what you want is the opposite of ignoring whitespace.You cannot tell
scanfto error out on a whitespace, but you can detect how many whitespace characters were consumed. For example:This detects whitespace before the second input.
Having said that, erroring out on whitespace is probably not a good idea.