I have a structure Item with the following members.
struct Item{
char *name;
int price;
double weight;
};
Another structure Inventory with the following members.
struct Inventory{
struct Item **item;
int NUMITEMS;
};
I have a function addItem() which takes the Inventory* as its parameter.
void addItem(struct Inventory* i){
printf("Enter Name:");
scanf("%s",i->item->name);
printf("Enter Price");
scanf("%d",i->item->price);
printf("Enter Weight");
scanf("%lf",i->item->weight);
}
The main objective of the function is to assign the values to the member of Item structure. How can I do so? I want to set the values of the members of the Item structure through the double pointer of type item from a function. My entire code is:
#include<stdio.h>
struct Item{
char *name;
int price;
double weight;
};
struct Inventory{
struct Item **item;
int NUMITEMS;
}inventory1;
struct Character{
char *name;
int Level;
long XP;
struct Inventory inventory;
};
void createCharacter(struct Character* c){
printf("Enter Name:");
c->name = (char*) malloc(40*sizeof(char));
scanf("%s",c->name);
printf("Enter Level:");
scanf("%d",&c->Level);
printf("Enter XP:");
scanf("%ld",&c->XP);
}
void viewCharacter(struct Character* b){
printf("%s level %d with %ld XP",b->name,b->Level,b->XP);
}
void addItem(struct Inventory* i){
i->item =(struct Item*)malloc(i->NUMITEMS*sizeof(struct Item));
printf("Enter name:");
scanf("%s",i->item->(*name));
}
void viewItem(struct Inventory* i){
//yet to write
}