Created
January 10, 2015 22:15
-
-
Save kenornotes/8f4fcbfda1e9e678a69e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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