-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];
}; 
4
  • 6
    What happened when you tried to compile code using this? Commented Oct 16, 2019 at 13:29
  • 2
    Possible duplicate of Initialize values of array in a struct Commented Oct 16, 2019 at 13:33
  • Short answer: yes, you can define and use a struct like that. Commented Oct 16, 2019 at 13:34
  • The word is "medicine". Commented Oct 16, 2019 at 14:47

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

5 Comments

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 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.
Dont have one, just powerpoint from teachers lectures but they are hard to understand
Then it's high time to get one.
do you have skype

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.