Created
August 29, 2018 13:57
-
-
Save ppmx/e4cf941d137df0bed979c0d922941c54 to your computer and use it in GitHub Desktop.
just an example how to use strtok
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
| /* % ./a.out "hello, world. this is an example" ".," | |
| * hello | |
| * world | |
| * this is an example | |
| */ | |
| #include <stdio.h> | |
| #include <string.h> | |
| int main(int argc, char **argv) | |
| { | |
| if (argc < 3) | |
| return fprintf(stderr, "Usage: %s <input> <tokens>\n", argv[0]); | |
| for (char *ptr = strtok(argv[1], argv[2]); ptr; ptr = strtok(NULL, argv[2])) | |
| printf("%s\n", ptr); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment