strtok(NULL)
时间: 2023-11-04 20:53:18 浏览: 27
strtok(NULL) is a function used to continue tokenizing a string after the initial call to strtok().
The strtok() function is part of the C standard library and is used to split a string into smaller tokens based on a specified delimiter. On the first call to strtok(), you pass the input string as the first argument and the delimiter as the second argument. It returns a pointer to the first token found in the input string.
To continue tokenizing the string, subsequent calls to strtok() should pass NULL as the first argument instead of the input string. This tells the function to continue tokenizing from the last position it left off.
Here's an example:
```c
#include <stdio.h>
#include <string.h>
int main() {
char str[] = "Hello, World! How are you?";
char delimiters[] = " ,!?";
char* token = strtok(str, delimiters);
while (token != NULL) {
printf("%s\n", token);
token = strtok(NULL, delimiters);
}
return 0;
}
```
In this example, the strtok() function is used to tokenize the string "Hello, World! How are you?" using delimiters such as space, comma, and exclamation mark. The first call to strtok() returns "Hello" and subsequent calls using strtok(NULL, delimiters) will return "World", "How", "are", and "you".