sizeof
是字符串空间大小,比如一个char t[300],大小是300,一个int,大小是4字节
strlen
char t[300]="";
strlen(t)为0
sprintf_s(tmp,300,"%s",r)
tmp和r都是char []
300是tmp大小,以上函数作用是将r内容写入tmp,适用于多个参数写入一个字符串
strtok
函数原型:chstrtokar *strtok(char *s, const char *delim);
Function:分解字符串为一组字符串。s为要分解的字符串,delim为分隔符字符串。
Description:strtok()用来将字符串分割成一个个片段。参数s指向欲分割的字符串,参数delim则为分割字符串,当strtok()在参数s的字符串中发现到参数delim的分割字符时 则会将该字符改为\0 字符。在第一次调用时,strtok()必需给予参数s字符串,往后的调用则将参数s设置成NULL。每次调用成功则返回被分割出片段的指针。
1 //借助strtok实现split
2 #include <string.h>
3 #include <stdio.h>
4
5 int main()
6 {
7 char s[] = "Golden Global View,disk * desk";
8 const char *d = " ,*";
9 char *p;
10 p = strtok(s,d);
11 while(p)
12 {
13 printf("%s\n",p);
14 p=strtok(NULL,d);
15 }
16
17 return 0;
18 }