C语言 strtok函数分解字符串为一组字符串
一、SYNOPSIS
#include <string.h>
char *strtok(char *str, const char *delim);
二、DESCRIPTION
The strtok() function breaks a string into a sequence of zero or more nonempty tokens. On the first call to strtok() the string to be
parsed should be specified in str. In each subsequent call that should parse the same string, str must be NUL
三、strtok函数功能是分解字符串为一组字符串。s为要分解的字符串,delim为分隔符字符(如果传入字符串,则传入的字符串中每个字符均为分割符)。首次调用时,s指向要分解的字符串,之后再次调用要把s设成NULL。
四、测试
1、strtok.c
#include "stdio.h"
#include "stdlib.h"
#include<string.h>
void main()
{
int i;
char*freq_split;
char cpu_clus0_freqs[]="/sys/devices/system/cpu/cpufreq/policy0/interactive/boostpulse";
printf("\n c strtok function! cpu_clus0_freqs=%s\n",cpu_clus0_freqs);
printf("\n************************************\n");
freq_split = strtok(cpu_clus0_freqs,"/");
while(freq_split)
{
printf("[%d]%s\n",i,freq_split);
freq_split=strtok(NULL,"/");
i++;
}
printf("\n************************************\n");
printf("\n c strtok function! cpu_clus0_freqs=%s\n",cpu_clus0_freqs);
}
2、运行结果