My Subject Blog

C Program to Copy String Using Pointer

/*
Write a program using a pointer to copy one string to another string. 
*/

#include <stdio.h>

int main(void) 
{
 char str1[50],str2[50];
 int i,j;
 char *p,*q;
 printf("\n Enter First String : ");
 scanf("%s",str1);

 p=str1;
 q=str2;

 for(i=0;*(p+i)!='\0';i++)
 {
     *(q+i)=*(p+i);
 }

*(q+i)='\0';

 printf("Copied String = %s",q);
 return 0;
}

Comments

Most Visited Post

C Program to Find Largest Odd Number from Array

C Program for Runtime Memory Allocation for Table of Integers

Followers