C++ Program to Copy String Without Using strcpy

C++ program to copy one string into another 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

Recommended Posts
C++ Program to Check whether a string is Palindrome or Not
C++ Program to find length of string
C++ Program to Print Array in Reverse Order
C++ Program to Delete Vowels Characters from String
C++ Program to Count Words in Sentence
C++ Program to Delete a Word from Sentence
C++ Program to Delete Spaces from String or Sentence
C++ Program to Convert Decimal Number to Binary Number
C++ Program to Remove all Non Alphabet Characters from a String
All C++ Programs