I'm trying to match my input with 3 variable types: an integer, a float and a string.
char *input = "1 5.456 oxygen\0";
int i = sscanf(input, "%d %f %[^\0]", &id, &dens, name);
if (i != 3)
break;
This works great if input does contain all these 3 types and I use the value returned by sscanf in order to check this.
But if input is missing the integer at the beginning such as:
char *input = " 5.456 oxygen\0";
the variable i will still be equal to 3 because sscanf will match id with 5 and dens with .456.
What is the best way to use sscanf so it checks for whitespaces between the required types (at least one or more whitespaces).
scanf(). Your best option is to usefgets()and a parser (which can be as simple asstrtol(),strtod(),strcpy()). - pmg