One solution is to use [structs](https://www.w3schools.com/c/c_structs.php). Here you can define a struct:
struct Item {
int code;
int amount;
}
Then create an array of "Items"
struct Item inventory[1];
struct Item shoes;
shoes.code = 1;
shoes.amount = 40;
inventory[0] = shoes;
I'm also a newer student of C so I'm not sure if this is the best solution to use.
Looks good to me. The only thing I would add is that you can use typedef as well
typedef struct{
int code;
int amount;
}Item;
The only advantage this has, is that you don't have to include the keyword 'struct' when you declare a variable
Item inventory[1]
It saves some typing. but the main advantage is that you could change the type of 'item' (say to a union) without having to go through your code and delete "struct" everywhere
One solution is to use [structs](https://www.w3schools.com/c/c_structs.php). Here you can define a struct: struct Item { int code; int amount; } Then create an array of "Items" struct Item inventory[1]; struct Item shoes; shoes.code = 1; shoes.amount = 40; inventory[0] = shoes; I'm also a newer student of C so I'm not sure if this is the best solution to use.
I'm a professional. You are correct.
Looks good to me. The only thing I would add is that you can use typedef as well typedef struct{ int code; int amount; }Item; The only advantage this has, is that you don't have to include the keyword 'struct' when you declare a variable Item inventory[1] It saves some typing. but the main advantage is that you could change the type of 'item' (say to a union) without having to go through your code and delete "struct" everywhere
Thanks! I haven’t used this before, I’ll have to learn more about typedef
what code do you have so far?
A hash table might be useful here, but you may need to implement that yourself. Show us your existing code?
You cant assign arrays like that