If I understand correctly, you need to use some kind of delimiter to split the string in substrings. For example, "one # two # three" crashed in two three. If yes:
#include <stdio.h>
#include <string.h>
int main()
{
char test[] = "one#two#three";
char* res;
res = strtok(test, "#");
while(res) {
printf("%s\n", res);
res = strtok(NULL, "#");
}
return 0;
}
You call strtok () once with the line you want tokenize. Each of the following calls must pass NULL to continue the line from the first call. Also note that strtok can change the original pointer, so if it is dynamically allocated, you must save it before passing it to strtok.
source
share