strtok()函数不能直接处理const char*, 用strncpy得到一个char型数组, 对这个temp数组进行处理即可。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main (void)
{
char *string = "T01:91+:123";
char tmp[16];
char* s;
/* Strtok can not do with const char*, so I use strncpy copy it to an char array */
strncpy(tmp, string, sizeof(string));
s = strtok (tmp, "T");
printf("string: %s\n", string); // 01:91+:123
s = strtok (s, ":");
printf("city id: %s\n", s); // 01
return 0;
}
|