Two-dimensional char array

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jun 2007
Posts: 18
Reputation: pixrix is an unknown quantity at this point 
Solved Threads: 0
pixrix pixrix is offline Offline
Newbie Poster

Two-dimensional char array

 
0
  #1
Jul 3rd, 2007
What is a two-dimensional char array with 3 rows and 3 columns. Can give me an example of a program. Thanks
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,632
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1496
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Two-dimensional char array

 
0
  #2
Jul 3rd, 2007
I won't write the program for you but here is how to declare the array.

  1. char array[3][3];
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 18
Reputation: pixrix is an unknown quantity at this point 
Solved Threads: 0
pixrix pixrix is offline Offline
Newbie Poster

Re: Two-dimensional char array

 
0
  #3
Jul 3rd, 2007
I also know how to wirte it.. but wat is it use for.. can at least show me some example..
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,649
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 474
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: Two-dimensional char array

 
0
  #4
Jul 3rd, 2007
A real world use of two dimensional arrays is for representing matrices. Here is an example of 3 x 3 identity matrix:
  1. int matrix[3][3] = {0};
  2. for(int i = 0; i < 3; ++i)
  3. {
  4. for(int j = 0; j < 3; ++j)
  5. {
  6. if(i == j)
  7. matrix[i][i] = 1;
  8. }
  9. }
  10.  
  11. //For printing this matrix
  12. for(int i = 0; i < 3; ++i)
  13. {
  14. for(int j = 0; j < 3; ++j)
  15. {
  16. cout << " " << matrix[i][j]) << " ";
  17. }
  18. putchar('\n');
  19. }

The output after printing this matrix would be:
  1. 1 0 0
  2. 0 1 0
  3. 0 0 1
Last edited by ~s.o.s~; Jul 3rd, 2007 at 1:33 pm.
I don't accept change; I don't deserve to live.

Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,632
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1496
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Two-dimensional char array

 
0
  #5
Jul 3rd, 2007
2 dimensional character arrays can be used to store any list of text items, such as a list of people's names, a list of addresses, telephone numbers, email addresses, etc. If you want a list of 3 names and each name can be a maximum of 20 characters then you would declare the array like below -- since c style strings must be terminated with a NULL character -- '\0' -- you must add one extra byte to the maximum width you want, in this example declare the width as 21 characters.
  1. char names[3][21];
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 18
Reputation: pixrix is an unknown quantity at this point 
Solved Threads: 0
pixrix pixrix is offline Offline
Newbie Poster

Re: Two-dimensional char array

 
0
  #6
Jul 5th, 2007
Thanks guys
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC