Originally posted by quzah
A structure is a group of variables bundled by a common name. Consider:
There. You have a vehicle. You can name your vehicle. You can give it different numbers of wheels, and you can give it a miles per gallon.Code:struct vehicle { char *name; int wheels; float milesPerGallon; };
Let's say we want to make a whole list of cars at once. We will create an array of vehicles.
There you go. You have a bunch of vehicles. They're all defined.Code:struct vehicles cars[] = { { "Sports Car", 4, 25.5 }, { "Family Car", 4, 30.1 }, { "Semi Trailer", 18, 11.7 }, { "Motorcycle", 2, 40.3 }, { "Econo-Car", 4, 55.9 } };
You can simplify this process by defining the structure and creating the array all in one shot:
See?Code:struct vehicle { char *name; int wheels; float milesPerGallon; } vehicles[] = { { "Sports Car", 4, 25.5 }, { "Family Car", 4, 30.1 }, { "Semi Trailer", 18, 11.7 }, { "Motorcycle", 2, 40.3 }, { "Econo-Car", 4, 55.9 } };
[edit]
Ah. Took too long replying.
[/edit]
Quzah.
oh Thank you guys.........you've all been a big help, how would I access an instance of a car with this?