sscanf won't *require* a space
I want to scan text input for a command followed by hexadecimal numbers. My format string has a space separating the word and the %x, but sscanf won't require it. If the word ends with [abcdef], sscanf takes that as a hexadecimal number instead of part of the word.
For example, here's the format string: "en %X %X". If the input text is "en 3 4", it works as expected, but if the input is "enc 3 4", sscanf sees that as the word "en" followed by the hex number "c". I want it to not match because "enc" != "en". Since the space after "en" in the format string was ignored, I set "Scanf Classes Supported" = yes and tried many variations of explicitly specifying that I require a space there ("%[ ]", "%*[]", "%*[ \t]"), but nothing works. (But they do work in Visual C++.)
sscanf("en 3 4", "en %X %X", &x, &y); // x=3, y=4. OK.
sscanf("enc 3 4", "en %X %X", &x, &y); // x=12, y=3. Not OK.
sscanf("enc 3 4", "en%*[ ]%X %X", &x &y);// Same result: x=12, y=3.
How do I get sscanf to require a space where I've specified?
Please sign in to leave a comment.
Comments
1 comment