I have a structure where I have char ** inside it , I have another pointer of type char * How can I assign value to it ? I tried strcpy() but it is giving me error argument of type "char **" is incompatible with parameter of type "char *".
struct tmp{
char **ptr1;
int x ;
}
void foo( struct tmp *t, char *ptr){
t->ptr1 = ptr;
t->x = 0;
}
I tried with strcpy() but getting error
Can someone help me out here .
>Solution :
You need to alocate the space for the pointer.
void foo( struct tmp *t, char *ptr)
{
t->ptr1 = malloc(sizeof(*t -> ptr1);
*t->ptr1 = ptr;
t->x = 0;
}