C Program to Copy String to New String

In this program, you'll learn to how to copy given string into new string without using strcpy() function.



Source Code
#include<stdio.h>

int main()
{
    int i;
    char copy[30], paste[30];

    printf("Enter the string to copy: ");
    gets(copy);

    for(i=0; copy[i] != '\0'; i++)
    {
        paste[i] = copy[i];
    }
    paste[i] = '\0';

    printf("Copied string is: ");
    puts(paste);
    return 0;
}
Output
Enter the string to copy: Sample String
Copied string is: Sample String





"Coding Hub - Learn to code" app now available on Google Play Store