Say you have a program like this
#include <stdio.h>
int
main (void)
{
char **foo;
foo = malloc (100);
foo[0] = "cat";
foo[1] = "dog";
foo[2] = "bird";
return 0;
}
How could you iterate the array, for example printing all the elements, without hard coding the upper bound?
Since you want to do :
which stores the address of string literal into the elements of array foo, each element of the array must be of type char pointer. But you are doing:
which makes each element of foo a char and not char pointer.
What you need it:
To iterate over the filled elements of the array, you can keep an explicit counter equal to the number of elements filled