Answer to Question #260593 in C++ for mannya

Question #260593

Write a function to concatenate two strings. (Don’t use predefined functions)

Char* strcat(char *dest,const char *source);


1
Expert's answer
2021-11-03T04:22:05-0400
#include<iostream>
using namespace std;

int main()
{
	const char* a="Wonderful";
	const char* b=" world";
	int sizeA,sizeB;
	for(sizeA=0;a[sizeA]!='\0';sizeA++);
	for(sizeB=0;b[sizeB]!='\0';sizeB++);
	char result[sizeA+sizeB+1];
	int i=0;
	for(;i<sizeA;i++)
	{
		result[i]=a[i];
	}
	for(int j=0;j<sizeB;j++,i++)
	{
		result[i]=b[j];
	}
	result[i]='\0';
	cout<<"Result of two strings concstenation is: "<<result<<endl;
}

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
New on Blog
APPROVED BY CLIENTS