I have a very simple problem that I cannot seem to figure out. I have this:
char* array[10];
So, I then have 10 char*
pointers on the stack. Now all I want to do is allocate memory for each pointer. As in:
array[0] = malloc(sizeof(char)*6);
And then store some characters at this location:
strncpy(array[0], "hello", sizeof("hello"));
Yet, I am getting a compile-time error at the first step of allocating the memory:
error: invalid conversion from ‘void*’ to ‘char*’ [-fpermissive]
But it works as expected at Ideone.
What am I doing wrong? I understand what I am trying to do, but I do not understand why it does not work. At each index in array
there is a char*
. By using the =
symbol I am trying to assign each pointer to a block of memory allocated to it.
What am I doing wrong? Compiling with g++ -g -Wall