So I have an assignment to allocate enough memory to store a set of structs with different values in them. I am only allowed to call malloc once.
A have a struct that looks like this:
typedef struct ObjectTag Object;
struct ObjectTag
{
char *stringA[20];
char *stringB[30];
char *stringC[5];
unsigned short num;
};
For my malloc call I am doing
Object *myObjArray;
myObjArray= (Object*)malloc(numObjects * sizeof(Object));
I am trying to get information from an infile to place into my structs. Thus I am doing
fscanf(inFile, " %s", (*Object)[i].stringA);
fscanf(inFile, " %s", (*Object)[i].stringB);
fscanf(inFile, " %s", (*Object)[i].stringC);
fscanf(inFile, " %hu", (*Object)[i].num);
and so on in a loop.
But when I try to compile I get this error
format '%s' expects argument of type 'char *', but argument 3 has type 'char **'
and also this for the last one
format '%hu' expects argument of type 'short unsigned int *', but argument 3 has type 'int'
I have no idea what I'm doing wrong.
Notes that may be relevant:
- The infile has an expected format to it
- I have counted how many structs I needed as noted by the numObjects in the malloc call