I'm relatively new to C. I'm trying to pass an address of a variable to a function, and then have that function assign a char pointer to this variable address which was passed. The compiler doesn't complain, but the code doesn't work properly either.
typedef enum {
VAL_1,
VAL_2
} member_type;
char *a1="Test 123";
int func (member_type x, char *temp) {
switch(x) {
case VAL_1:
temp = a1;
return 1;
case VAL_2:
return 2;
}
return 0;
}
int main(){
member_type b;
static char *d1;
b = VAL_1;
printf("%p\n",&d1);
func(b, &d1);
printf("Val_1:%s\n",d1);
return 0;
}
I get the following error when I execute it:
-bash-3.00$ ./a.out
0x500950
Name:(null)
Can anyone help me with how to fix it?