new to this forum sorry if i did anything wrong just looking for some help.
im writing a program that reads in from a file a certain number of products and a certain number of months that those products were sold for.....ive created the following struct
Code:
typedef struct{
int ID;
char *name;
float *unit_prices;
int *units_sold;
}product;
void read_data(product info[], int *Num_Products, int *Months);
/*this reads in the data from the file and assigns Num_Products and months
its value which then dynamically creates space to hold the rest of the information from the file*/
int main(void)
{
int Num_Products;
int Months;
product *info;
info = (product *) malloc(sizeof(product) * Num_Products);
info->unit_prices = (float*) malloc(sizeof(float) * Months);
/*this is were my problem is.....i figured this would create space
for months inside each struct that i create but i realized its only
creating space for unit_prices inside struct info[0] not the other
structs created thats when i tried to use a for statement*/
for(index = 0; index < Num_Products; index++)
{
for(index2 = 0; index2 < Months; index2++)
{
(info + index) -> unit_prices[index2] = (float*)
malloc(sizeof(float) * Months);
}
}
any hints or help on how i should approach this is greatly appricated thanks