Answer to Question #188873 in C++ for Asad

Question #188873

Write a program that take input two strings from the user, copy first string in second string and second string in first one


1
Expert's answer
2021-05-09T13:03:04-0400
#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);
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS