原型:
char *strtok(char s[], const char *delim);
作用:
分解字符串爲一組字符串。s
爲要分解的字符串,delim
爲分隔符字符串。
例如:
strtok("abc,def,ghi", "," )
,最後可以分割成爲abc def ghi.
示例:
#include <stdio.h>
#include <string.h>
int main()
{
char str[1024];
char world[] = ",";
printf("please enter strings:");
fgets(str, 1024, stdin);
char *p = strtok(str,world);
while(p)
{
printf("%s\n",p);
p = strtok(NULL,world);
}
return 0;
}
運行:
please enter strings:abc,def,ghi
abc
def
ghi