The following piece of code produces a segmentation fault during compilation:
(gdb) run
Starting program: /home/anna/Desktop/a.out
Program received signal SIGSEGV, Segmentation fault.
0xb7e97845 in strtok () from /lib/i386-linux-gnu/libc.so.6
#include <string.h>
#include <stdio.h>
main () {
char * sentence = "This is a sentence.";
char * words[200] ;
words[0] = strtok(sentence," ");
}
After changing the 5th line, no error is thrown.
#include <string.h>
#include <stdio.h>
main () {
char sentence[] = "This is a sentence.";
char * words[200] ;
words[0] = strtok(sentence," ");
}
Why is this happening?