how to copy pointer to pointer.

char *name1;               //store the value of DAVE
char *name2;              

if name2 was a array i would have done.

strcpy(name2,name1);

but i dont know how to copy pointer into pointer.

i was thinking some thing like this.

name2 = name1?

also do i need to test malloc for name2?

A pointer is just a variable, so coping a pointer into a pointer is done just like you showed.

    char *name1; 
    char *name2; 

    name2 = name1;

Now both name2 and name1 point to the same memory area.

By using assignment operator, name2 will now point to the same address of name1. So, No use of malloc.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.