strtok函数(C)

原型:char *strtok(char s[], const char *delim); (在string.h函数库里

分解字符串为一组字符串。s为要分解的字符,delim为分隔符字符(如果传入字符串,则传入的字符串中每个字符均为分割符)。首次调用时,s指向要分解的字符串,之后再次调用要把s设成NULL。


例如:

#include
#include
int main(void)
{
	char str[10] = "asdc##dsf";
	char *p;

	p = strtok(str, "##");
        if(p)  printf("%-7s", p);

	p = strtok(NULL, "##");
        if(p)  printf("%s\n", p);

        return 0;
}

 
  

结果为: strtok函数(C)_第1张图片

 
  
 
  


你可能感兴趣的:(C学习笔记)