*string_ptr[4], pointer of chars
Hi there,
I have been using pointers of "strings" (formally chars) before, but assigning the values with a direct asignation (see ex. below); now though, I need to assign the values only once they are available, that means that I'd like to use a strcpy to do that.
Well, I get a bus error and I can't explain why.
I'd appreciate it if someone were able to help
thanks in advance
1) Exemple 1: Direct assignment of strings: This works fine
Code:
const char *varnames[] = {"HOLA", "HAYA", "CIAO"};
2) Case that gives BUS error:
Code:
//DEclaration
char *FLAG[nbdy_nodes];
//Allocation
for(i=0; i<3; i++)
FLAG[i] = (char*) malloc(4 * sizeof(char));
//Assignment:
strcpy(bdy_FLAG[1], "1111");
//or strcpy(*FLAG[1], "1111");
Thank you