0 like 0 dislike
7 views
Hello. It's late and maybe I'm a little bit slow but somehow can't think of how to do the following:

for example in a text file in two-dimensional Cartesian coordinate system presents a simple maze in the form of units (walls), zeros(rooms) and f (finish).So deuce is located at coordinate (4,5)

1,1,1,2,1,1

1,0,0,0,0,1

1,0,1,1,0,1

1,0,0,1,0,1

1,1,1,1,1,1

How to convert this set of numbers in a two-dimensional array so that each value of the array had the key in the Cartesian coordinate system? Ie to deuce was in array[4][5]
| 7 views

0 like 0 dislike
``for(j=5;j>=1;j--) for(i=1;i<=6;i++) scanf("%i",&array[i][j]); ``

Something like that.
by
0 like 0 dislike
Don't understand why you can't just read the file as usual?
by
0 like 0 dislike
If we know beforehand the size of the maze (or can read), then you just need to record the address of matrix[n – i – 1][j] (can be added to each index unit to the numbering went from 1, but then the memory need to allocate more of — (n + 1) * (m + 1)).
\r
If the size of the matrix is unknown in advance, and to determine its dimension we need in the process of reading, it is better, I think, to read the matrix as usual, and then wrap it in a class with get and set methods (or, if the language allows you to set the getters and setters), which already produce the necessary offset based on the size of the matrix to be stored in the same class.
by

0 like 0 dislike