Create a method called concat that takes three char array pa

Create a method called “concat” that takes three char array parameters. This method should concatenate the second string on to the end of the first string and store the result in the third string. Note: When you concatenate two string you add the contents of one string on to another. Important: Make sure you add null terminators where necessary. No pointer.C++

Solution

#include <iostream>
#include <cstring>
using namespace std;
void concat(char first[], char second[], char third[]) {
for(int i=0; i<strlen(first); i++){
third[i]=first[i];
}
for(int j=strlen(first)-1,i=0; i<strlen(second); i++,j++){
third[j]=second[i];
}
}

int main()
{
char first[] = \"Abcd\";
char second[] = \"Efgh\";
char third[strlen(first)+strlen(second)];
concat(first, second, third);
cout<<\"Third array content is \"<<third<<endl;
return 0;
}

Output:

sh-4.2$ g++ -o main *.cpp                                                                                                                                                                                                                                              

sh-4.2$ main                                                                                                                                                                                                                                                           

Third array content is AbcEfgh

Create a method called “concat” that takes three char array parameters. This method should concatenate the second string on to the end of the first string and s

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site