strsep(),作为strtok的升级版,是一个很有用的字符串处理函数
man strsep:
#include <string.h>
char*strsep(char **stringp, const char *delim);
Be cautious when using this function. If you do use it, note that:
This function modifies its first argument.
This function cannot be used on constant strings.
The identity of the delimiting character is lost.
#include <stdio.h>
#include <string.h>
int main(void)
{
char s[] = "hello world!";
char *p = s;
char *d = " ";
printf("%s\n", strsep(&p, d));
printf("%s\n", p);
return 0;
}
函数打印如下:helloworld!