As mentioned above double pointer not equal to 2D array.
You can also use pointer to pointer of char. char **history. And with this you have several option:
1) Use compound literals
#include <stdio.h>
void render_history(const char **history, const int entry)
{
printf("%s\n", history[entry]);
}
int main(void)
{
const char **history = (const char *[]) { "1234", "5678", "9012", NULL};
render_history(history, 2);
return 0;
}
If you need change your data later
2) Use dynamic memory allocation with malloc
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void render_history(char **history, const int entry)
{
printf("%s\n", history[entry]);
}
int main(void)
{
char **history = malloc(3 * sizeof(char *));
for (int i = 0; i < 3; ++i)
{
history[i] = malloc(4 * sizeof(char));
}
strcpy(history[0], "1234");
strcpy(history[1], "5678");
strcpy(history[2], "9012");
history[3] = NULL;
render_history(history, 2);
return 0;
}
If you use 2nd option dont forget free memory after use.
mainfunction? Theargvargument? It's an array of strings, an array of pointers. Which seems to be what you want instead of an array of arrays of pointers. What you have now is, basically, somewhat equivalent to a 3d array.char *(notchar), so the needed parameter type would bechar * history[][4], or, equivalently,char * (*history)[4].historydecays to a pointer to an arrays of four pointers,char *(*)[4], which is very different fromchar **. If you had e.g.char history[3][5], orchar *history[3]it would be a very different matter.