C Programming c programming notes for gate C programming Tutorials gate study material for cse

Program to copy the contents of one string to another string using a pointer

A C program to copy the contents of one string to another using a pointer method is:


 

 
#include
#include
#include
#define length 50
 
void main()
{
char *s1,*s2,c;
int i=0;
clrscr();
s1=(char*)malloc(length*sizeof(char));
s2=(char*)malloc(length*sizeof(char));
printf(“enter stringn”);
gets(s1);
while((c=*(s1+i))!=”)
{
s2[i]=c;
i++;
}
s2[i]=”;
printf(“Copied string isn”);
printf(“%s”,s2);
getch();
}
 
 

Leave a Reply

Your email address will not be published. Required fields are marked *