Copy String Without Using strcpy() in C++ Prog

04-11-17 Course- CPP

In this program you can use the standard library function strcpy() to copy the content of one string to another but, this program copies the content of one string to another manually without using strcpy() function.

Source Code to Copy String Manually


#include <iostream>
using namespace std;
int main()
{
    char s1[100], s2[100];
    int i;
    cout << "Enter string s1: ";
    cin >> s1;
    for(i=0; s1[i]!='\0'; ++i)
    {
        s2[i]=s1[i];
    }
    s2[i]='\0';
    cout << "String s2: " << s2;
    return 0;
}

Output


Enter String s1: fastread 
String s2: fastread 

This above program copies the content of string s1 to string s2 manually.