C Tutorial/string.h/strtok
Версия от 14:21, 25 мая 2010; (обсуждение)
Using strtok
#include <stdio.h>
#include <string.h>
int main()
{
char string[] = "asd fasd fasdf asdfads fasdf";
char *tokenPtr;
printf( "%s\n%s\n\n%s\n",
"The string to be tokenized is:", string,
"The tokens are:" );
tokenPtr = strtok( string, " " );
while ( tokenPtr != NULL ) {
printf( "%s\n", tokenPtr );
tokenPtr = strtok( NULL, " " );
}
return 0;
}
The string to be tokenized is: asd fasd fasdf asdfads fasdf The tokens are: asd fasd fasdf asdfads fasdf