C Programming Code Examples C > Strings Code Examples Program to copy string using pointer Program to copy string using pointer Write a C program to copy one string to another string using loop. C program to copy one string to another without using inbuilt library function strcpy(). How to copy one string to another without using inbuilt string library function in C programming. Effective logic to copy strings in C programming. How to copy one string to another string using strcpy() function in C program. Logic to copy one string to another string Input string from user and store it to some variable say text1. Declare another variable to store copy of first string in text2. Run a loop from 0 to end of string. The loop structure should be like for(i=0; text1[i] != '\0'; i++). Inside the loop for each character in text1 copy to text2. Say text2[i] = text1[i]. Finally after loop make sure the copied string ends with NULL character i.e. text2[i] = '\0';. /* C program to copy one string to another string using pointer */ #include <stdio.h> #define maxsize 100 // Maximum size of the string int main() { char text1[maxsize], text2[maxsize]; char * str1 = text1; char * str2 = text2; /* Input string from user */ printf("Enter any string: "); gets(text1); /* Copy text1 to text2 character by character */ while(*(str2++) = *(str1++)); printf("First string = %s\n", text1); printf("Second string = %s\n", text2); return 0; }