2d array struct giving a segmentation fault
<p>This program fragment should be reading in information in structs which are stored in a 2d way.
But this program fragment gives a segmentation fault after "printf("lel4\n");".
I have the feeling it is in my memory allocation, but I don't know. I looked for answers on the internet and I am doing exactly the same thing as the given answers, but it isn't working.</p>

<pre><code>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&lt;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&lt;col;i++){
        c = getchar();
        for(j = 0; j&lt;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;
}
</code></pre>