-
sscanf question
Since a string is not a stream how do I get sscanf to traverse the string rather than keep reading the first thing? I want to use the following while loop but because of this problem it goes infinite
Code:
while((sscanf(myString, "%s", anotherString)) != EOF){
.
.
.
}
Thanks
-
sscanf never returns eof, it returns the count of
variables it managed to scan in.
Try
Code:
while (sscanf (......) != 0)
{
.
.
.
.
}
-
Thats not the problem.
It doesnt traverse the string because it is not a stream. Everytime sscanf is executed, it reads the same thing each time.
-
Something like
Code:
int pos = 0;
char *p = myString;
while ( sscanf( p, "%s%n", anotherString, &pos ) == 1 ) {
// do stuff
p += pos; // advance p
}
%n tells you how many chars sscanf() processed
-
Ok i see why that works but why do I check if it equals 1?
-
> Ok i see why that works but why do I check if it equals 1?
Because I've read the sscanf() manual page, and you haven't...