使用数组下标时转储Segmentation Fault核心

时间:2011-09-19 15:09:55

标签: segmentation-fault core

我正在尝试实施一个相当基本的程序,但我正在获得一个倾销核心。关于我做错的任何想法?

#include <stdio.h>

int
main(void){


    char *number [] = {"one","two","three","four","five","six","seven","eigth","nine"};
    char *object [] = {"sf","sfe","sefg","efsef","seg","eshse","segeg","ryte","asrh","asegh"};

    for(int i=0;i<10;i++){

        printf("In this code %s\n this should %s\n work\n\n",number[i],object[i]);


    }


}

2 个答案:

答案 0 :(得分:1)

Joe说得对:你的循环gos从0到9,即10个项目。你想要0到8。

这是一个真正常见的初学者错误。

模式是

for index = 0; while index is less than length; add one to index

答案 1 :(得分:1)

你有一个经典的'一个接一个'的错误。 “number”数组中的元素太少。 object中有十个元素,number中只有九个元素。