I'm having problem with storing values in multi dimensional arrays. I need to have 10 * 10 array with rows and columns. I have intitialized the array with blank spaces " ". But after this I need to store letters like 'A' 'C' 'S' on specific locations in that array.

for example

0 1 2 3 4 5 6 7 8 9
0
------------------------------------------
1
-------------------------------------------
3
--------------------------------------------
4
--------------------------------------------
5
------------------------------------------
6
-------------------------------------------
7
-------------------------------------------
8
--------------------------------------------
9
--------------------------------------------

First question, do I print this layout board using for loop?

Second, that how would i put character 'A' in location Row = 0 and Column = 5???

and then display it

I know these questions are really basic but I'm just a beginner.
Thanks

3
Contributors
5
Replies
6
Views
9 Years
Discussion Span
Last Post by Aia

You can traverse a two-dimensional array with a nested loop:

``````for ( i = 0; i < 10; i++ ) {
for ( j = 0; j < 10; j++ )
printf ( "%c ", array[i][j] );
}``````

>Second, that how would i put character 'A' in location Row = 0 and Column = 5???
Assuming it's a two-dimensional array of char or int:

``array[0][5] = 'A';``
``````for ( i = 0; i < 10; i++ ) {
for ( j = 0; j < 10; j++ )
printf ( "%c ", array[i][j] );
}``````

Is this the initializing process?

Thanks for your help though.

>Is this the initializing process?
No, that would allow you to print every element of a multi-dimensional array of 10 by 10.
But you can use the same construct of two for loops to assign values to each element.

Oh, ok. Thanks

Another question I would like to ask is that...assuming I have stored specific values in the 10*10 array, and I want the user to guess their locations on the array until he runs out of given tries////how can I do that?

Should I use while loop for tries?
But I would like some hint how to put user provided rows and column and compare it with values on my 10*10array?

I would appreciate some help.

I am not quite sure I understand what you are asking.
Could you rephase differently, or better yet give us an example of what you what to achieve?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.