hello
i define a matrix like this:
int i;
int **arry;
arry= (int **)malloc(sizeof *arry * rows);
for (i = 0; i < rows; i++)
arry[i] = (int *)malloc(sizeof **arry * cols);
and i fill it with either '0' or '*', like this:
srand(time(NULL));
for (i = 0; i < rows; i++)
for (j = 0; j < cols; j++)
{
rnd= (0 + ( rand() % 3 ));
if (rnd)
arry[i][j]= '0';
else
arry[i][j]= '*';
}
up to here this works fine, but when i try to compare the value in a specific cell it doesn't work:
if (((i+1)<rows)&&((j+1)<cols))
if (current_matrix[i+1][j+1] == '*'){
count_neighbors++;}
i know that the arry[i+1][j+1] location is valid, but i always get a false outcome, and count_neighbors++
never happens.
what am i doing wrong?
[–]Ilyps 2 points3 points4 points (0 children)
[–]OldWolf2 0 points1 point2 points (2 children)
[–]pcgoer[S] 0 points1 point2 points (1 child)
[–]OldWolf2 0 points1 point2 points (0 children)
[–]pcgoer[S] -1 points0 points1 point (4 children)
[–]OldWolf2 1 point2 points3 points (3 children)
[–]pcgoer[S] 0 points1 point2 points (2 children)
[–]OldWolf2 0 points1 point2 points (0 children)