C++ Program to Copy String Without Using strcpy

In the previous article, we have discussed C++ Program to Concatenate Two Strings. In this article, we will see C++ Program to Copy String Without Using strcpy.

C++ Program to Copy String Without Using strcpy

  • Write a C++ program to copy one string into another string without using strcpy.

C++ program to copy string without using strcpy

C++ program to copy string without using strcpy

#include <iostream>
 
using namespace std;
 
int main(){
    char source[1000], copy[1000];
    int index = 0;
     
 cout << "Enter a string" << endl;
    cin.getline(source, 1000);
    // Copy String 
    while(source[index] != '\0'){
        copy[index] = source[index];
        index++;
    }
    copy[index] = '\0';
    cout << "Input String: " << source << endl;
    cout << "Copy String: " << copy;
      
    return 0;
}

Output

Enter a string
APPLE
Input String: APPLE
Copy String: APPLE

The popular Examples of C++ Code are programs to print Hello World or Welcome Note, addition of numbers, finding prime number and so on. Get the coding logic and ways to write and execute those programs.