K
Kelly B
I need a function which returns me a "word" from a given string and
then sets the pointer to the next one which is then retrieved during
further calls to the function.
I think strtok( ) is the solution but i could not understand the use of
the function as given in the C99 standard
EXAMPLE
#include <string.h>
static char str[] = "?a???b,,,#c";
char *t;
t = strtok(str, "?"); // t points to the token "a"
t = strtok(NULL, ","); // t points to the token "??b"
t = strtok(NULL, "#,"); // t points to the token "c"
t = strtok(NULL, "?"); // t is a null pointer
suppose i have a string " The C Programming Language"
how do i use strtok( ) to retrieve one word at a time from the string i.e
1st call :The
2nd call :C
3rd call rogramming
4th call :Language
Can anyone please help me out?
then sets the pointer to the next one which is then retrieved during
further calls to the function.
I think strtok( ) is the solution but i could not understand the use of
the function as given in the C99 standard
EXAMPLE
#include <string.h>
static char str[] = "?a???b,,,#c";
char *t;
t = strtok(str, "?"); // t points to the token "a"
t = strtok(NULL, ","); // t points to the token "??b"
t = strtok(NULL, "#,"); // t points to the token "c"
t = strtok(NULL, "?"); // t is a null pointer
suppose i have a string " The C Programming Language"
how do i use strtok( ) to retrieve one word at a time from the string i.e
1st call :The
2nd call :C
3rd call rogramming
4th call :Language
Can anyone please help me out?