So for the last several hours I have been trying to figure out why I was getting a seg fault while printing a freshly tokenized string using strtok(). FINALLY I realized I was not including string.h. After adding this line, I get the expected behaviour and no more seg fault... yay! However, I am new to c (although not programming) if someone could please explain the behaviour I was experiencing and answer the following...
- Why was I not receiving an error when calling strtok() when it was not included?
I read recently that if you do not include the string.h, the default method signature will be used. However, I want to use strtok()'s default sig so why am I still getting this undefined behaviour?
char str[]= "ls -l"; char * p = strtok (str, " "); printf ("%s\n",p);
Seg fault on the last line