pointer to pointer that points to a char array
Hello,
I have been experimenting with pointer to pointers that point to an int. That bit I understand.
However, when I try and dereference the pointer to get the string value, the program crashes.
Code:
void error_msg(char **msg)
{
printf("**msg: %s\n", **msg); //dereference to get the string
printf("*msg: %p\n", *msg); //display the address
}
I am calling the function like this:
Code:
char msg_error[] = "Message";
char *msg = msg_error;
error_msg(&msg);
When I was experimenting with integers I was doing like this:
Code:
void error_int(int **myInt)
{
//**myInt dereferences and *myInt displays the address
printf("*myInt address: %p value: %p\n", myInt, *myInt);
printf("**myInt address: %p value: %d\n", *myInt, **myInt);
}
I guess for arrays you have to do something different.
Many thanks,
Steve