trouble reading .txt into matrix

Hi all,
Im reading in from a text file that is formatted like this

1 1 1 1 1 1 4 7 8 X
6 1 1 1 1 1 1 5 8 8
1 1 1 1 1 1 1 4 6 7
1 1 1 1 1 X 1 1 3 6
1 1 1 1 1 X 1 1 1 1
1 1 1 1 1 1 1 1 1 X
6 1 1 1 1 X 1 1 1 1
7 7 1 X X X 1 1 1 1
8 8 1 1 1 1 1 1 1 1
X 8 7 1 1 1 1 1 1 1

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:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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.
Last edited on
try to put a space after the last X. hope you get what I mean.
I ended up putting the map into an array and the project is all done now, thanks sharma.
Topic archived. No new replies allowed.