I'm new to c and trying to create the minesweeper game. I think my code has some problems with the data type conversion but I don't understand why. Checked this link
How to cast or convert an unsigned int to int in C?
and tried to implement the info in my code.
I'm trying to implement a function that returns the number of neighboring locations of a x,y coordinated 2D array that have mines.
int neighbours(const Field *f, unsigned int x, unsigned int y)
{
int z = 0;
int i,j;
unsigned int a = y-1;
j =(int)a;
unsigned int b =x-1;
i = (int)b;
for(; j<=(a+2); j++){
if(j>=0 && j<=f->ysize){
for (; i<=(b+2); i++){
if ( i>=0 && i<=f->xsize && (f->places[j][i] == UNKNOWN_MINE ||f->places[j][i] == KNOWN_MINE)){
z++;
}
}
i = b;
}
}
return z;
}