The following code returns a segmentation fault and I don't get why. This is pretty much as the most examples I found online, so what's going on?
#include <stdio.h>
#include <string.h>
int main(int argc, char * argv) {
char * mystring = "a b c";
char* p = strtok(mystring, " ");
while(p != NULL) {
printf("%s\n", p);
p = strtok(NULL, " ");
}
return 0;
}
I compiled the go with cc -g tokenize.c -o mytokenize
. I tried to do a bit of debugging. The only thing I can say for sure is that is failing on strtok(mystring, " ");
.
Can someone tell me what I am doing wrong?