So I’m wondering how sscanf functions when faced with a line like this:
sscanf(input_string, "%s %s %s", cmd1, cmd2, cmd3);
But say the input_string only contains 1 string token. What values are assigned to cmd2 and cmd3? Is there an error thrown?
I’m using the GNU C compiler.
Nothing will be assigned to the extra parameters. The return from
sscanftells you how many conversions were done successfully, so in this case it would return1. You typically just compare to the number you expect, and assume the input is bad otherwise:When you’re reading from a file, you often want to execute in a loop until you get correct input: