原型:extern char *strtok(char *s, char *delim);
用法:#include <string.h>
功能:分解字符串為一組標記串。s為要分解的字符串,delim為分隔符字符串。
說明:首次調用時,s必須指向要分解的字符串,隨后調用要把s設成NULL。
strtok在s中查找包含在delim中的字符并用NULL('\0')來替換,直到找遍整個字符串。
返回指向下一個標記串。當沒有標記串時則返回空字符NULL。
舉例:
// strtok.c
#include <syslib.h>
#include <string.h>
#include <stdio.h>
main()
{
char *s="Golden Global View";
char *d=" ";
char *p;
clrscr();
p=strtok(s,d);
while(p)
{
printf("%s\n",s);
strtok(NULL,d);
}
getchar();
return 0;
}
相關函數:strcspn , strpbrk
|