Более универсальный способ, исользуя функцию strtok:
char string[] = "A string\tof ,,tokens\nand some more tokens";
char seps[] = " ,\t\n";
char *token;
void main( void )
{
printf( "Sourse: %s\n\nTokens:\n", string );
/* Establish string and get the first token: */
token = strtok( string, seps );
while( token != NULL )
{
/* While there are tokens in "string" */
printf( " %s\n", token );
/* Get next token: */
token = strtok( NULL, seps );
}
}
Output -
Sourse: A string of ,,tokens
and some more tokens
Tokens:
A
string
of
tokens
and
some
more
tokens