Advertisement
char * strcat ( char * destination, const char * source )
// Program to concatenate values in two char array with string values */
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
char dest[10] = "Hello";
char src[10] = "World";
cout<<"The value in destination string : " <<dest << "\n";
cout<<"The second in source string : " <<src << "\n";
strcat(dest,src);
cout<<"Concatenated strings : " << dest;
return 0;
}
First String value : Hello
Second String value : World
Concatenated strings : HelloWorld
Advertisement
// Program to append one string at the end of another string withut strcat() function
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
char dest[20] = "Hello";
char src[10] = "World";
cout<< "The value in dest string : " << dest << "\n";
cout<< "The second in src string : " << src << "\n";
int len1 = strlen(dest);
int len2 = strlen(src);
cout<< "Length of characters in dest string : " << len1 << "\n";
cout<< "Length of characters in src string : " << len2 << "\n";
for(int i=0;i<len2; i++)
{
dest[len1] = src[i];
len1 = len1 + 1 ;
}
dest[len1]='\0';
cout<< "Concatenated strings : " << dest;
return 0;
}
The value in dest string : Hello
The second in src string : World
Length of characters in dest string : 5
Length of characters in src string : 5
Concatenated strings : HelloWorld
Advertisement
Advertisement
Please check our latest addition
C#, PYTHON and DJANGO
Advertisement