Hi
I am fairly new to C and have come up against 'pointers of pointers'.
I understand the concept (I think) but am baffled by the example given in my text book. If any of you can help i would really be pleased. Here's the code, sorry its a bit long...
#include <stdio.h>
void StrPrint1(char **str1, int size); /*HERE BEGINS MY PROBLEM*/
void StrPrint2(char *str2);
main()
{ /*declare and initialise pointer array*/
char *str[4] = { "first line", "second line",
"third line",
"last line\n"
};
int i, size = 4;
StrPrint1(str, size); /*call function and pass args*/
for( i=1; i<size; i++)
StrPrint2(str[i]);
return 0;
}
void StrPrint1(char **str1, int size)
{
int i;
/*print all strings in an array of pointers to strings*/
for(i=0; i<size; i++)
printf("%s\n", str1[i]);
}
void StrPrint2(char *str2)
{
/*prints one string at a time*/
printf("%s\n", str2);
}
Essentially what I don't get is the **str1 thing. Is it a pointer which points to the address of the array of pointers *str[4]?
Why is it never assigned to anything?
Or is it referring to str[4] as a 'pointer of pointers'?
I think you can tell I am confused so the simpler the answers the better.
buck71