You can't assign to char
arrays like that, you need one of the string operations, such as:
strcpy (database.name, line); // or "->" if database is pointer
(preferably checking the length beforehand to ensure no buffer overflow, or using a safer function depending on your needs).
It's also bad form to cast the return value from malloc
in C since it can hide certain subtle errors. It's acceptable if your code has to also compile in C++ but you just need to ensure you have the correct prototype in scope.
In terms of the initialisation error, I suspect that you have the declaration at file level (outside of any function). This means you can't use a function call to initialise it since it has static storage duration and wants to be set before any code runs.
You can get around that problem thus:
// At file level:
label* allLabels = NULL;
// In your function:
void addLabel(char line[], char type[], int addr) {
if (allLabels == NULL) {
allLabels = malloc (sizeof(label) * 10);
if (allLabels == NULL) {
// malloc failed, do something to recover.
}
}
// And we don't need local storage here, hit the array directly.
strcpy (allLabels[arrayIndex].name, line);
strcpy (allLabels[arrayIndex].type, type);
allLabels[arrayIndex].address = addr;
arrayIndex++;
}
This uses a constant initialiser NULL
to set the value and you then just need to ensure it's allocated before the first time you use it.