User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 456,553 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,493 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser: Programming Forums
Views: 705 | Replies: 5
Reply
Join Date: Oct 2007
Posts: 28
Reputation: Sh13 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
Sh13 Sh13 is offline Offline
Light Poster

Problem with multiDimensional array?

  #1  
Oct 17th, 2007
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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Sep 2004
Posts: 6,515
Reputation: Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of 
Rep Power: 31
Solved Threads: 489
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Expert Meanie

Re: Problem with multiDimensional array?

  #2  
Oct 17th, 2007
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';
I'm here to prove you wrong.
Reply With Quote  
Join Date: Oct 2007
Posts: 28
Reputation: Sh13 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
Sh13 Sh13 is offline Offline
Light Poster

Re: Problem with multiDimensional array?

  #3  
Oct 17th, 2007
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.
Reply With Quote  
Join Date: Dec 2006
Posts: 1,569
Reputation: Aia is a splendid one to behold Aia is a splendid one to behold Aia is a splendid one to behold Aia is a splendid one to behold Aia is a splendid one to behold Aia is a splendid one to behold Aia is a splendid one to behold 
Rep Power: 12
Solved Threads: 114
Aia's Avatar
Aia Aia is offline Offline
Posting Virtuoso

Re: Problem with multiDimensional array?

  #4  
Oct 17th, 2007
>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.
At the very moment that I find myself in the side of the mayority, I will know that I need to re-think my ideas. ~ In my book.
Reply With Quote  
Join Date: Oct 2007
Posts: 28
Reputation: Sh13 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
Sh13 Sh13 is offline Offline
Light Poster

Re: Problem with multiDimensional array?

  #5  
Oct 17th, 2007
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.
Last edited by Sh13 : Oct 17th, 2007 at 8:43 pm.
Reply With Quote  
Join Date: Dec 2006
Posts: 1,569
Reputation: Aia is a splendid one to behold Aia is a splendid one to behold Aia is a splendid one to behold Aia is a splendid one to behold Aia is a splendid one to behold Aia is a splendid one to behold Aia is a splendid one to behold 
Rep Power: 12
Solved Threads: 114
Aia's Avatar
Aia Aia is offline Offline
Posting Virtuoso

Re: Problem with multiDimensional array?

  #6  
Oct 18th, 2007
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?
At the very moment that I find myself in the side of the mayority, I will know that I need to re-think my ideas. ~ In my book.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C Forum

All times are GMT -4. The time now is 5:19 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC