Computer Science, asked by monishapandey78, 2 months ago

how to initialize structure in run time?​

Answers

Answered by IceWeb
2

You cannot initialize a structure like that at run time.

example:

struct item_info

{

char itemname[15];

int quantity;

float retail;

float wholesale;

}item[NOOFITEM];

int main()

{

item[0]={"rice",10,40,30};

item[1]={"sugar",10,40,30};

item[2]={"soap",10,40,30};

}

But if you want to assign values at run time then you have to do it manually like:

strcpy(item[0].itemname, "rice");

item[0].quantity = 10;

item[0].retail = 40;

item[0].wholesale = 30;

Similar questions