I was doing one problem(Minesweeper) from Steven Skiena(Programming Challenges). Where you have to output the number of mines adjacent to that square.
#include<iostream>
using namespace std;
int main()
{
int n,m;
cin>>m>>n;
char a[m][n];
for(int i=0;i<m;i++)
{
for (int j = 0; j < n; j++)
{
cin>>a[i][j];
}
}
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
if(a[i][j]!='*')
{
int no=0;
if(a[i-1][j-1]=='*')
no++;
else if(a[i][j-1]=='*')
no++;
else if(a[i+1][j-1]=='*')
no++;
else if(a[i+1][j]=='*')
no++;
else if(a[i+1][j+1]=='*')
no++;
else if(a[i][j+1]=='*')
no++;
else if(a[i-1][j+1]=='*')
no++;
else if(a[i-1][j]=='*')
no++;
a[i][j]=(char)no;
}
}
}
for(int i=0;i<m;i++)
{
for (int j=0; j<n; j++)
{
cout<<a[i][j];
}
cout<<endl;
}
return 0;
}
When I try to run this program, the array where the mines isn't placed are blank. Is it something related to the casting of integer to character?