Linux C数据解析函数strtok():解析字符串

头文件:#include <string.h>

函数原型:char* strtok(char* s,const char* delim)

函数功能:分解字符串为一组字符串,s为要分解的字符串,delim为分隔符字符串

返回值:成功则返回下个目录进入点. 有错误发生或读取到目录文件尾则返回NULL.

范例:

#include<stdio.h>
#include<string.h>
int main(void)
{
    char buf[]="aaa,bbb,ccc,ddd";
    char*temp = strtok(buf,",");
    while(temp)
    {
        printf("%s ",temp);
        temp = strtok(NULL,",");
    }
    return0;
}

运行结果:aaa  bbb  ccc  ddd

(效果有点类似于将delim用\n替换)

猜你喜欢

转载自blog.csdn.net/qq_35769746/article/details/81303590