I have an assignment were I have to write a program in C that ask's a user to input up to 5 vehicles and each vehicle can have up to 8 models associated to it - each model will also contain extra data.
So I thought about creating and array of MAX 5 structs (for the vehicles) and inside each vehicle structure create another array of MAX 8 structs (for each vehicle's model's).
The problem is, I don't know how to keep track of the number of models that have been created inside each vehicle. I can keep track of the number of vehicles by using a counter that increments by 1 each time the 'vehicle input' function is called. But I just can't work out how to keep track of the number of models inserted for each vehicle...
This is a prototype of how I originally declared the data structure:
What would be the best approach to designing a data structure for a program with this type of functionality?
I'm kind of new to C so please go easy on me
Any help would be apreciated!!
So I thought about creating and array of MAX 5 structs (for the vehicles) and inside each vehicle structure create another array of MAX 8 structs (for each vehicle's model's).
The problem is, I don't know how to keep track of the number of models that have been created inside each vehicle. I can keep track of the number of vehicles by using a counter that increments by 1 each time the 'vehicle input' function is called. But I just can't work out how to keep track of the number of models inserted for each vehicle...
This is a prototype of how I originally declared the data structure:
Code:
/********************************
VARIABLES AND CONSTANTS
********************************/
const int MAXVEHICLES = 5;
const int MAXMODELS = 8;
/********************************
DATA STRUCTURES
********************************/
struct modelData{
int hp;
int weight;
int maxSpeed;
};
struct modelType{
char modelName[50];
struct modelData data;
};
struct vehicles{
char vehicleName[50];
struct modelType model[MAXMODELS];
} vehicles[MAXVEHICLES];
I'm kind of new to C so please go easy on me
Any help would be apreciated!!