Skip to content

Instantly share code, notes, and snippets.

@EdoardoVignati
Created August 27, 2017 18:13
Show Gist options
  • Save EdoardoVignati/e662acabccb2d9750829ae685ee06c5b to your computer and use it in GitHub Desktop.
Save EdoardoVignati/e662acabccb2d9750829ae685ee06c5b to your computer and use it in GitHub Desktop.
Tokenize a string in c
#include <string.h>
#include <stdio.h>
int main()
{
char str[100] = "Try to token , this is a token , another token";
const char s[2] = ",";
char *token;
/* Get the first token */
token = strtok(str, s);
/* Walk through other tokens */
while( token != NULL )
{
printf("%s\n", token);
token=strtok(NULL, s);
}
return(0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment