Program to Copy one string to another using pointer.



/*Program to Copy one string to another using pointer.*/

#include
#include

main()
{
char a[80],b[80],*pa,*pb;
int i=0;
clrscr();
printf("Given first string ");
scanf("%s",a);
pa=&a[0];
pb=&b[0];
while(*pa!='\0')
{
*pb=*pa;
pa++;
pb++;
}
*pb='\0';
printf("\nCopied string is");
puts(b);
}

3 comments:

  1. if you explain the code it ll be more help ful.
    thnks for the code..........

    ReplyDelete
  2. Another way is :

    Under FOR loop
    First we take all values of string one into

    pointer------>pointer=string1;


    Then we copy all values in pointer to string

    two-------->pointer=scanf("%s",&string2);

    ReplyDelete