I dont know why the elements are not being scanned

0 Puneet Kaur · September 15, 2015
#include<math.h>
#include<stdlib.h>
//the bishop war
void main()
{
int row,column,i=0,j=0;
int k,l;

int board[10][10];

int rb=-1,cb;
printf("enter the no. of rows needed:");
scanf("%d",&row);
printf("enter the no. of columns needed:");
scanf("%d",&column);
printf("now enter the boards locations:");
printf("B=Bishop\n *=empty space\n .=other\n");

//entering the boards keys
for(i=0;i<row;i++)
{
for (j=0;j<column;j++)
{
scanf("%d",&board[j]);
printf("we are at %d,%d",i,j);
}

}
//finding the bishop's location
for(i=0;i<row;i++)
{
for(j=0;j<column;j++)
{
if(board[j]=='B')
{
rb=i;
cb=j;
}
}
}
//verifying the bishops presence and location
if(rb==-1)
{
printf("sorry the bishop wasnot found");
exit(0);
}
else 
{
printf("the bishop was found at %d row and %d colunm",rb,cb);
}
return ;
}

Post a Reply

Replies

Oldest  Newest  Rating
+1 Jon Z. · September 17, 2015

scanf("%d",&board[j]); ---> scanf("%d",&board[i][j]);
0 Puneet Kaur · September 17, 2015
oops :P i missed it and spent an hour finding no bug:).Thanks :)
  • 1

C

107,029 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator