2016-03-21 7 views
0

このプログラムフラグメントは、2d形式で格納されている構造体の情報を読み込む必要があります。 しかし、このプログラムフラグメントは、 "printf(" lel4 \ n ");"の後にセグメンテーションフォールトを与えます。 私はそれが私の記憶割り当てにあると感じていますが、わかりません。私はインターネット上の答えを探して、私は与えられた答えと全く同じことをやっているが、うまくいきません。セグメンテーションフォールトを与える2d配列構造体

typedef struct coordinates{ 
    int xposition;       
    int ypositiony;       
    char token;      
    int discovered;     
} coordinates 

typedef coordinates *coord; 

coord **allocMemory(int row, int col){ 
    int i; 
    coord **city = malloc(sizeof(coord)*col); 
    assert(city != NULL); 
    for(i=0; i<col; i++){ 
     city[i] = malloc(sizeof(struct coordinates)*row); 
     assert(city[i] != NULL); 
    } 
    return city; 
} 


coord **readInfo(int row, int col){ 
    int i, j; 
    char c; 
    coord **city = allocMemory(row, col); 
    for(i=0; i<col;i++){ 
     c = getchar(); 
     for(j = 0; j<ros; j++){ 
      c = getchar(); 
      if(c == '#' || c == '.'){ 
       printf("lel4\n"); 
       (*city)[i][j].xposition = i; 
       printf("lel5\n"); 
       (*city)[i][j].yposition = j; 
       (*city)[i][j].token = c; 
       (*city)[i][j].discovered = 0; 
      } 
     } 
    } 
    return city; 
} 
+0

にコードには2次元配列と一つとして使用することができない、構築物はありません。 – Olaf

+0

**その都市は何をしていますか? – LifeisHard

+1

'coord **' - > 'coord *' – BLUEPIXY

答えて

0
coord ** 

coord *

city[i][j].xposition = i; 
city[i][j].yposition = j; 
city[i][j].token = c; 
city[i][j].discovered = 0; 
関連する問題