I am trying to copy a string to an array of string. I have used these two examples before and they have worked so I don't understand why they won't work this time. I am getting a segmentation fault.
http://stackoverflow.com/a/1088667/985898
http://stackoverflow.com/a/1095006/985898
I remembered to initialize everything.
char *strings_mneumonic_table[503] = {0};
char mneumonic[20] = {0};
int start_address = 0;
int hash = 0;
if(line[0] == 32)
{
printf("32 group \n");
sscanf(line, "%s %x", mneumonic ,&start_address);
printf("mneumonic is %s\n", mneumonic);
printf(" hash is %d \n", hash);
strcpy(strings_mneumonic_table[hash], mneumonic);
//printf("under strcpy(strings_mneumonic_table[hash], mneumonic); \n");
//hex_address_table[hash] = start_address;
//printf("hex_address_table[hash] = start_address; \n");
//printf("end of 32 group \n");
}
Here is my output
hash is 2
little start
BIG START
32 group
mneumonic is START
hash is 2
Segmentation fault (core dumped)