char *strtok( char *strToken, const char *strDelimit ); Parameters strToken String containing token or tokens. strDelimit Set of delimiter characters. locale Locale to use. Return Value Returns a pointer to the next token found in strToken. They return NULL when no more tokens are found. Each call modifies strToken by substituting a NULL character for each delimiter that is encountered. // crt_strtok.c // compile with: /W3 // 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 string/tof ,,tokens/nand some more tokens"; char seps[] = " ,/t/n"; char *token; int main( void ) { printf( "Tokens:/n" ); // Establish string and get the first token: token = strtok( string, seps ); // C4996 // Note: strtok is deprecated; consider using strtok_s instead while( token != NULL ) { // While there are tokens in "string" printf( " %s/n", token ); // Get next token: token = strtok( NULL, seps ); // C4996 } } 输出 Tokens: A string of tokens and some more tokens #include <stdio.h> #include <string.h> int main() { char str[] = "abcd:12345"; char *dest=NULL; dest = strchr(str, ':'); puts(dest); return 0; } strchr返回找到的字符的第一个位置