I am trying to make a malloc based on a struct.
The struct looks like this:
struct shirts
{
char color[10];
int size;
};
struct shirts* ptr_shirts;
I then want to make x amount of t-shirts so i have a variable for that:
printf("How many T-shirts? ");
scanf("%d",&amount);
getchar();
ptr_shirts = (struct shirts *)malloc(amount * sizeof(struct shirts));
I then want to fille the spaces but i dont know how to do it. I have tried to use a for loop and put in values like it is an array:
for(i = 0; i<amount;i++)
{
printf("Color on T-shirt nr %d: ",(i+1));
scanf_s("%s", "what to type here" ,sizeof(ptr_shirts->color));
printf("Size on T-shirt nr %d: ",(i+1));
scanf("%d",&"what to type here");
}
i have tried with
ptr_shirts[i].size
ptr_shirts->size[i]
(ptr_shirts.size
and then ptr_shirts++)
but i dont know how to make it easy becuase i want to fill more then 1 t-shirt, thats the problem i got