Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/styllloz/public_html/qa-include/qa-base.php on line 1175

Warning: session_start(): Cannot start session when headers already sent in /home/styllloz/public_html/qa-include/app/users.php on line 162

Warning: Cannot modify header information - headers already sent by (output started at /home/styllloz/public_html/qa-include/qa-base.php:1175) in /home/styllloz/public_html/qa-include/app/users.php on line 1267

Warning: Cannot modify header information - headers already sent by (output started at /home/styllloz/public_html/qa-include/qa-base.php:1175) in /home/styllloz/public_html/qa-include/app/page.php on line 356
Like a maze from a text file to display in a two-dimensional array? - code-flow.club | Q&A

Like a maze from a text file to display in a two-dimensional array?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
10 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]
by | 10 views

3 Answers

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

Related questions

0 like 0 dislike
2 answers
0 like 0 dislike
1 answer
asked Aug 16, 2019 by respirant
0 like 0 dislike
1 answer
asked Jun 13, 2019 by koshak_junior
0 like 0 dislike
1 answer
110,608 questions
257,186 answers
0 comments
35,182 users