由於某些原因,我在此處收到了分段錯誤。我不知道爲什麼。任何幫助?無法解釋的分段錯誤
typedef struct gw_struct{
int pop;
int col;
int row;
struct district ***gw;
struct person **people;
};
typedef struct gw_struct *GW;
後來在功能
,然後...
GW world;
struct district ***array = malloc(nrows*sizeof(struct district**));
int i, j;
for (i = 0; i < nrows; i++)
{
array[i] = malloc(ncols*sizeof(struct district*));
for (j = 0; j<ncols; j++)
{
array[i][j] = malloc(sizeof(struct district));
}
}
world->gw = array; //this is the line that gives the seg fault
你有沒有intialise指針世界? – 999k 2013-03-11 05:51:48