Skip to content

Instantly share code, notes, and snippets.

@ppmx
Created August 29, 2018 13:57
Show Gist options
  • Select an option

  • Save ppmx/e4cf941d137df0bed979c0d922941c54 to your computer and use it in GitHub Desktop.

Select an option

Save ppmx/e4cf941d137df0bed979c0d922941c54 to your computer and use it in GitHub Desktop.
just an example how to use strtok
/* % ./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