-
strtok wont end!
i cant get strtok to end! in all the examples i found it ends but mine wont! i dont see it.
heres my code
Code:
test("-x,-y");
int test(char options[]) {
char *options_backup = malloc( strlen(options) + 1 );
strcpy(options_backup, options);
char *current = strtok (options_backup, ",");
while(current != NULL) {
printf ("%s\n", current);
current = strtok(NULL, ",");
}
return 0;
}
-
That works perfectly fine here, make sureyou #include the appropriate headers.
-
And don't forget to free() the memory you've malloc'd