I am trying to get this information into a int matrix replacing the X's with 10.
My code is working for everything except where I encounter an X in the last column and I cant work out why.
The section of code that I am having trouble with is:
int map[num_rows][num_cols];
// sort map data into a matrix
for (i=0;i<num_rows;i++)
{
for (j=0;j<num_cols-1;j++)
{
getline(fin,String,' ');
if (String.compare(wall)==0)
map[i][j]=10;
else
map[i][j]=atoi(String.c_str());
}
//j = 9
getline(fin,String,'\n');
cout<<"last string is "<<String<<endl; //this is to confirm last column
if (String.compare(wall)==0)
{cout<<"I IS "<<i<<" AND J IS "<<j<<endl;
map[i][j]=10;}
else
map[i][j]=atoi(String.c_str());
}
for (i=0;i<num_rows;i++)
{
for (j=0;j<num_cols;j++)
{
cout<<map[i][j]<<" ";
}
cout<<endl;
}
Note: for the compare function, wall="X"
Thanks in advance.