Skip to content

Instantly share code, notes, and snippets.

@wusuopubupt
Created July 15, 2014 09:04
Show Gist options
  • Save wusuopubupt/64cd0cb29bf67ed82af4 to your computer and use it in GitHub Desktop.
Save wusuopubupt/64cd0cb29bf67ed82af4 to your computer and use it in GitHub Desktop.
#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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment