Constants:
#define MAX_OPCODE_NAME_LEN 4
I have an array of structs:
OPCODE *mot[NUM_OPCODES];
Struct def:
typedef struct opcode {
char name[MAX_OPCODE_NAME_LEN + 1];
char format;
int type;
} OPCODE;
In my code:
strcpy(mot[0]->name, "hlt");
strcpy(mot[1]->name, "add");
strcpy(mot[2]->name, "sub"); // seg fault on this command
strcpy(mot[3]->name, "mul");
// ...more code follows
My code gives me a segmentation fault here and I'm not sure why, since it should have enough space to hold 5 characters (4 char followed by '\0'), so it shouldn't be running out of space, and I'm just copying a string literal into a static memory location. Perhaps I defined the struct incorrectly or used the pointer arrow in the wrong spot?
mot?OPCODE *mot[NUM_OPCODES];but that's all I did. Do i need to malloc something else for it?