次のコードでは、コンパイル中にセグメンテーション違反が発生します。
(gdb) runプログラムの
開始: /home/anna/Desktop/a.out
プログラムはシグナル SIGSEGV を受信しました。セグメンテーション違反です。
/lib/i386-linux-gnu/libc.so.6 からの strtok () の 0xb7e97845
#include <string.h>
#include <stdio.h>
main () {
char * sentence = "This is a sentence.";
char * words[200] ;
words[0] = strtok(sentence," ");
}
5 行目を変更した後、エラーはスローされません。
#include <string.h>
#include <stdio.h>
main () {
char sentence[] = "This is a sentence.";
char * words[200] ;
words[0] = strtok(sentence," ");
}
なぜこうなった?