Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can i Assign value to char** inside structure

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 .

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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;
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading