Write a program that take input two strings from the user, copy first string in second string and second string in first one
#include<iostream>
#include<string>
using namespace std;
void String_copy(char s1[],char s2[])
{
int i;
char temp[40];
for(i=0;s1[i]!='\0';i++)
{
temp[i]=s1[i];
}
for(i=0;s2[i]!='\0';i++)
{
s1[i]=s2[i];
}
for(i=0;temp[i]!='\0';i++)
{
s2[i]=temp[i];
}
cout<<"\nFirst String becomes "<<s1;
cout<<"\nSecond String becomes "<<s2;
}
int main()
{
char s1[40],s2[40];
cout<<"Enter first string ";
cin.getline(s1,40);
cout<<"\nEnter second string ";
cin.getline(s2,40);
String_copy(s1,s2);
}
Comments
Leave a comment