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!