Originally Posted by
blob84
nice msh, but inverting arr position:
Code:
while (*arr)
printf("%s\n", *arr++);
Yea. You're right.
But you can't really use this here; it'll segfault if it fails to run across a null byte before reaching the end of arr.
This is probably more correct.
Code:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
const int entries = 2;
char** arr = (char**)malloc(entries * sizeof(*arr));
arr[0] = "cane";
arr[1] = "dog";
int i;
for (i = 0; i < entries; ++i)
{
printf("%s\n", arr[i]);
}
return 0;
}