I'm having an entry level C pointer problem... Let's say I have two strings and I want to print them. What am I misunderstanding in the code below?
void print_array(char **array[]) {
int i = 0;
while((*array)[i] != NULL) {
printf("%s\n", (*array)[i++]);
}
return;
}
int main(int argc, char** argv) {
char str1[] = "hello";
char str2[] = "world";
char **array = {str1, str2};
print_array(&array);
return (EXIT_SUCCESS);
}
For my code to work I need to access the array like it is in print_array
Seg. Faultprint_array(char** array)andchar** array = {str1, str2, NULL}; print_array(array);return-statements are superfluous... Also, there's no percentage in normalizing a value in a boolean context.