Write a function to concatenate two strings. (Don’t use predefined functions)
Char* strcat(char *dest,const char *source);
#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;
}
Comments
Leave a comment