C++ Program to Copy String to Another String

Write C++ Program to Copy String to Another String

// CPP Program to Copy String to Another String

#include <iostream>
#include <string.h>

using namespace std;

int main()
{
	char S1[] = "CodeCrucks";
    cout << "String :--> : " << S1;

	char S2[50];
	int i = 0;

//	strcpy(ch,str);     // Using inbuilt function

    // Doing manually
	while(S1[i] != '\0')
	{
		S2[i] = S1[i];
		i++;
	}
	S2[i] = '\0';

    cout << "\nCopied String :--> : " << S2;

	return 0;
}

Output:

String :--> : CodeCrucks
Copied String :--> : CodeCrucks

≪ Previous | Next ≫