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<iostream>
using namespace std;

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

    cout<<"Enter the string to copy: ";
    gets(copy);

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

    cout<<"Copied string is: ";
    puts(paste);
    return 0;
}

Output
Enter the string to copy: Sample String
Copied string is: Sample String