I have this defined in my header file:
typedef struct Code {
char *data;
unsigned short size;
} Code;
And these two in my .c file:
typedef struct MemBlock {
char data[BLOCK_SIZE];
int bytesUsed;
struct MemBlock *next;
} MemBlock;
typedef struct CodeSet {
Code *codes;
MemBlock *memBlock;
int size;
int index;
} CodeSet;
I am trying to set the data in Code with something like:
mySet->codes[mySet->index]->size = 1;
but I get errors everytime I try to use -> after I put codes[]. What would the correct way be to do this?
You should use
->to access members in pointers tostruct. Since an array dereferenced isn’t a pointer, it should be accessed with.instead of->.Hence the correct syntax would be :
mySet->codes[mySet->index].size = 1;sincecodes[]is an array and not a pointer.