I have been trying to create a dynamically allocated array of struct type label
and have been failing miserably. In my .h file, I have:
typedef struct _label {
char name[256];
char type[256];
int address;
} label;
and in my .c file, I have this at the top:
label* allLabels = (label*) malloc(sizeof(label) * 10); // line 10
int arrayIndex = 0;
and finally, I have a function in the same .c file that is meant to add these struct objects to the array to be used by other methods in the file:
void addLabel(char line[], char type[], int addr) {
label database;
database.name = line; // line 805
database.type = type; // line 806
database.address = addr;
allLabels[arrayIndex] = database;
arrayIndex++;
}
Basically I just want to have a collection of accessible labels. Can someone help me understand what I'm doing wrong?
I get these errors, and I haven't forgotten any of the necessary #include statements either:
formatBuilder.c:10:3: error: initializer element is not constant
formatBuilder.c: In function 'addLabel':
formatBuilder.c:805:18: error: incompatible types when assigning to type 'char[256]' from type 'char *'
formatBuilder.c:806.18: error: incompatible types when assigning to type 'char[256]' from type 'char *'