Nothing will be assigned to the extra parameters. The return from sscanf
tells you how many conversions were done successfully, so in this case it would return 1
. You typically just compare to the number you expect, and assume the input is bad otherwise:
if (3 != sscanf(input_string,"%s %s %s", cmd1, cmd2, cmd3))
fprintf(stderr, "Badly formatted input (expecting three strings)\n");
When you're reading from a file, you often want to execute in a loop until you get correct input:
while (3 != scanf("%s %s %s", cmd1, cmd2, cmd3))
fprintf(stderr, "Please enter 3 strings:");