I need to make a program that can register some car. Then I need show all the cars registeres.
I can't make this work, when I execute the code below the printf show just memory trash, and just the last car appears right!
Code (I have a menu function that call the others):
int id = 0;
struct car {
char brand[50];
char model[50];
};
car *garage = 0;
int doCar(){
garage = (struct car *)malloc(sizeof(struct car*));
printf("\n Insert the model: \n\n");
fflush(stdin);
fgets( garage[id].model, 50, stdin);
id++;
}
int ShowCars(){
int i = 0;
while (i < id) {
printf("aqi= %s \n", garage[id].model);
i++;
}
}