We will introduce the correct application method in detail in this article, hoping to help you and improve the actual program development efficiency.
The prototype of C ++ strtok is as follows:
Char * strtok (
Char * strToken,
Const char * strDelimit );
// Crt_strtok.c
/** // * In this program, a loop uses strtok
* To print all the tokens (separated by commas
* Or blanks) in the string named "string ".*/
# Include <string. h>
# Include <stdio. h>
Char string [] = "A stringtof, tokensnand some more tokens ";
Char seps [] = ", tn ";
Char * token;
Int main (void)
{
Printf ("Tokens: n ");
/** // * Establish string and get the first token :*/
Token = strtok (string, seps );
While (token! = NULL)
{/** // * While there are tokens in "string "*/
Printf ("% sn", token );
/** // * Get next token :*/
Token = strtok (NULL, seps );
}
}
C ++ strtok output:
A
String
Of
Tokens
And
Some
More
Tokens
Notes:
Strtok (char * strToken, const char * strDelimit) Where strToken and strDelimit must be in character array format. That is to say, the entry can only be the character array element address.