let's say I have an array in C:
char *list[3] = {"Hello", "world", "!"};
And I want to expand it. If I daclare that array as:
char **list = (char **) malloc(3 * sizeof(char *)); // Or sth. like that...
I can resize it:
realloc(list, 5 * sizeof(char *)); // Not sure now if I should use `char *` or `char **`
If I try this:
char *list[3] = {"Hello", "world", "!"};
realloc(list, 5 * sizeof(char *)); // Not sure now if I should use `char *` or `char **`
It says that it can't resize memory that wasn't allocated.
Ok, but how can I then resize an array like this?
sizeof(char *)correctly. A better and safer way would be to usesizeof *listinstead.