Skip to content

Instantly share code, notes, and snippets.

@kenornotes
Created January 10, 2015 22:15
Show Gist options
  • Save kenornotes/8f4fcbfda1e9e678a69e to your computer and use it in GitHub Desktop.
Save kenornotes/8f4fcbfda1e9e678a69e to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <string.h>
//use strtok(string.h) to split token
//reference: http://www.cplusplus.com/reference/cstring/strtok
int main() {
char str[] = "this is token test";
char str2[] = "it will show how to split string";
char * token;
//type 1
token = strtok( str, " " );
printf ( "%s\n",token );
token = strtok ( NULL, " " );
printf ( "%s\n",token );
token = strtok ( NULL, " " );
printf ( "%s\n",token );
token = strtok ( NULL, " " );
printf ( "%s\n",token );
//type 2
token = strtok( str2, " " );
while ( token != NULL ) {
printf ( "%s\n",token );
token = strtok ( NULL, " " );
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment