Say that I have the string:
char* foo = " blah blee bleck ";
Now say that I want to read and throw away the first two words:
int bar = 0;
sscanf(foo, "%*s%n", &bar);
foo += bar;
if(bar > 0) sscanf(foo, "%*s%n, &bar);
My question is how can I tell if the second sscanf
read anything?
Do I need to 0 out bar
in between each read to determine if a string was actually read, or is there a better way?
EDIT:
Checking the sscanf
return value will not work because %*s and %n do not increase sscanf
's return value:
printf("%d ", sscanf(foo, "%*s%n", &bar));
printf("%d ", bar);
printf("%d ", sscanf(foo + bar, "%*s%n", &bar));
printf("%d\n", bar);
Will output:
0 6 0 6