G
gyan
Hi
How strtok track through string?
char *strtok(char *s1, const char *s2);
As i know
The first call (with pointer s1 specified) returns a pointer to the
first character of the first token, and will have written a null character
into s1 immediately following the returned token. The function keeps track
of its position in the string between separate calls, so that
subsequent calls (which must be made with the first argument being a
null pointer) will work through the string s1 immediately following
that token.
Now suppose i have
char *ptr = "Hello:world";
char *str = "Drop:me";
printf("\n%s",strtok(ptr,":"));
printf("\n%s",strtok(str,":"));
above 2 lines will give output as
Hello
Drop
Now if i want to call strtok to get next part of string "ptr", what i
should do?since calling
printf("\n%s",strtok(NULL,":"))
will give 2nd part of str and not of ptr.
How strtok track through string?
char *strtok(char *s1, const char *s2);
As i know
The first call (with pointer s1 specified) returns a pointer to the
first character of the first token, and will have written a null character
into s1 immediately following the returned token. The function keeps track
of its position in the string between separate calls, so that
subsequent calls (which must be made with the first argument being a
null pointer) will work through the string s1 immediately following
that token.
Now suppose i have
char *ptr = "Hello:world";
char *str = "Drop:me";
printf("\n%s",strtok(ptr,":"));
printf("\n%s",strtok(str,":"));
above 2 lines will give output as
Hello
Drop
Now if i want to call strtok to get next part of string "ptr", what i
should do?since calling
printf("\n%s",strtok(NULL,":"))
will give 2nd part of str and not of ptr.