Ok I went through the source code again and found the bug, forgot to increment the nRow
in GetData(void)
. These tiny bugs are creepy! So here are the modified parts of the code, now it works perfectly. nRow
must be increased once because I use an extra row for the Header
of each column.
void GetData(void){
int pos,k;
scanf("%d%d",&nCol, &nRow);
nRow++;//this is the change
for(int i=0 ; i<nCol ; i++)
Data[0][i] = true;
for(int i=1 ; i<nRow ; i++){
scanf("%d",&k);
for(int j=0 ; j<k ; j++){
scanf("%d",&pos);
Data[i][pos-1] = true;
}
}
CreateToroidalMatrix();
}
and this loop in CreateToroidalMatrix()
for(a=0 ; a<nRow ; a++) // removed equal sign
Since nRow was one less than it should've been, the inline functions used to get the neighbours, specifically dataUp()
and dataDown()
returned unexpected values.