I am new to C and cannot let my life determine what I'm doing wrong here. The first scanf works fine, variables print when they are read. The second scanf doesn't seem to read the input correctly. The input has the format "char int int", i.e. B 4 4
when I print opb x and y out, opb = "", x = 13238272, y = 0. Any ideas? ..... please note that cut the code below the problem
int main(void)
{
int width, height;
char op;
scanf("%c %d %d", &op, &width, &height);
if (op != 'g' || width>100 || height>100 || width*height<10 || width<1 || height<1) {
printf("grid-error\n");
return 0;
}
int grid[width][height];
char printGrid[width][height];
int i, j;
for (i=0; i<height; i++) {
for (j=0; j<width; j++) {
grid[j][i] = 0;
printGrid[j][i] = '*';
}
}
printf("%c %d %d \n", op, width, height);
int k;
for (k = 0; k<10; k++) {
int x, y;
char opb;
scanf("%c %d %d", &opb, &x, &y);
if (opb != 'b' || x<0 || y<0 || x>(width-1) || y>(height-1) || grid[x][y] == 9) {
printf("mine-error\n");
return 0;
}
source
share