Code:
int addProduct(ProductArrType* productArr, char name, char category){
productArr->products[productArr->numProducts] = malloc(sizeof(ProductType));
productArr->products[productArr->numProducts]->name = name;
productArr->products[productArr->numProducts]->category = category;
return 1;
}
defs.h
Code:
#define MAX_RUNNERS 10
#define MAX_STR 30
typedef struct {
char category[MAX_STR];
} EntityType;
typedef struct {
char name[MAX_STR];
} ProductType;
typedef struct {
int numProducts;
ProductType *products[MAX_PRODUCTS];
} ProductArrType;
In C, string are passed around as char *'s. They are arrays of char
terminated with a NUL. Since you have a buffer, you need to
call the function strcpy() to copy your input strings to this buffer.
So the prototype for the fucntion should be
Code:
int addProduct(ProductArrType *productArr, const char *name, const char *category):
The const isn't strictly necessary but makes it clear that you are not
modifying the input string, you are taking a copy of them.