关于strtok 第二个参数问题
程序代码:
//声明 extern int spitString(const char *str, char c, char **myp, int *count); int main() { char str[] = "asdas,12qwe,rer5434,2343fd,sdvg,gg,g"; char c = ','; int count; char *myp[7]; //判断函数是否成功执行 int er = spitString(str,c,myp,&count); if (er != 0) { printf("spitString err %d",er); return -1; } //打印*mup[7]每一行 for (int i = 0; i < 7; i++) { printf("%s ",*(myp+i)); } printf(" 行数: %d\n",count); system("pause"); return 0; } int spitString(const char *str, char c, char **myp, int *count) { if (str == NULL || c == NULL || myp == NULL || count == NULL) { return -1; } char *s = str; char *p; int i = 0; //这里 这里 //p = strtok(s, ","); p = strtok(s, c); for (i = 0; p != NULL; i++) { *(myp + i) = p; //这里 这里 //p = strtok(NULL,","); p = strtok(NULL,c); } *count = i; return 0; }
p = strtok(s, ",");和p = strtok(NULL,c); 用","便没问题 为什么啊? 有大佬给解解惑吗?
[此贴子已经被作者于2019-3-13 17:53编辑过]