| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
C/C++: Multi-dimensional array or struct?
Hi all,
I am using Microsoft VC++ 6.0 and not using MFC. I need to create some way of counting the number of animals that a person has, and also keep track of the state where the person lives. The fields/variables are: 1. char State[256] (there will be up to 50 states and each will be a maximum of 256 characters) 2. char PetOwner[256] (in this example, there will be up to 30 pet owners' names and each will be a maximum of 256 characters) 3. int Dogs (this is a counter for the number of dogs that a pet owner has) 4. int Cats (this is a counter for the number of cats that a pet owner has) 5. int Birds (this is a counter for the number of birds that a pet owner has) 6. int Weight (this is the weight of each pet) To get the above info, I am parsing a text file and it is working just fine. Now I need to put each piece of data into its respective variable so that I can create a pie chart later. That will be another topic. :-) Here's an example of what the text file looks like: Code:
Colorado, Bob Johnson, Dog, 30 lbs Colorado, Bob Johnson, Cat, 12 lbs Colorado, Debbie Smith, Dog, 15 lbs Colorado, Debbie Smith, Dog, 25 lbs Washington, George Jones, Cat, 10 lbs Washington, George Jones, Cat, 15 lbs Washington, George Jones, Bird, 3 lbs Any ideas of how I should go about creating a multi-dimensional array or struct? Thanks, bobert |
|
#2
|
|||
|
|||
|
I would use a class, then you can use an array to store objects of the class, I find that more intuitive than a multi array. For example:
#include <string> using std::string; class PetOwnerInfo { public: string State; string PetOwner; int Dogs; int Cats; int Birds; int Weight; }; Hope that helps... |
|
#3
|
|||
|
|||
|
Quote:
Hi, Yes, that did work. Thanks! bobert |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > C/C++: Multi-dimensional array or struct? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|