-10

So i am trying to make a code which lets the user register different medecines. Each medecine is gonna be a struct called medecine. The user can input the name of the medecine which is max 20 letters, the different sizes the medecine comes in, and how many there is of each size. I was thinking of something like this V. When i later want to use functions to store medecine input in a larg array which can hold 1000 medecines, is this gonna work ?

struct medecine
{ 
 char name[WORDLENGTH];
 int size[10];
 int BalanceOfeachsize[10];
}; 
mrarray
  • 1
  • 1
  • 2

1 Answers1

1

Yes of course it will work.

struct medecine
{ 
 char name[WORDLENGTH];
 int nbofsizes;           //  this is missing (see explanation below)
 int size[10];
 int BalanceOfeachsize[10];
}; 

struct medecine pharmacy[1000]:   // pharmacy is an array of 1000 medecines

But you most likely need one more struct member that is the number of sizes, maybe some meds come only in 3 sizes, others in 2 etc.

Jabberwocky
  • 48,281
  • 17
  • 65
  • 115
  • The user itself inputs which sizes they should come in and the balance of that size. So if i later want to limit each medecine to only 10 different sizes i can use the nbofsizes integer and limit it? Also why the second struct? Can i not add an array[1000] in int main and store all structs there? example medecine Medregister[1000] – mrarray Oct 16 '19 at 14:28
  • @mrarray yes, of course you can do that. Generally you can do a lot of things in C. From your questions I suppose you never opened your beginner's C text book. You should definitely do that. – Jabberwocky Oct 16 '19 at 15:26
  • Dont have one, just powerpoint from teachers lectures but they are hard to understand – mrarray Oct 16 '19 at 16:39
  • Then it's high time to get one. – Jabberwocky Oct 16 '19 at 16:41
  • do you have skype – mrarray Oct 16 '19 at 18:29