Write a C++ program to copy first string into second string, where first string is entered by the user.

Program Code:
#include<iostream>
#include<string.h>
#include<stdio.h>
using namespace std;
int main()
{
char str1[25], str2[25];
cout<<"Enter a string to copy into another string : ";
gets(str1);
cout<<endl;
cout<<"Copying string1 into string2 : ";
cout<<endl;
strcpy(str2, str1);
cout<<"String2 after copying String1 into it is : "<<str2;
return 0;
}

The program output is tested on www.jdoodle.com

Output:
Enter a string to copy into another string : Mukesh Rajput
Copying string1 into string2 : 
String2 after copying String1 into it is : Mukesh Rajput


Thanks
Mukesh Rajput
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: