Advertisement
char * strcat ( char * destination, const char * source )
/* Program to concatenate values in two char array with string values */
#include<string.h>
#include<stdio.h>
int main()
{
char dest[10] = "Hello";
char src[10] = "World";
printf("The value in destination string : %s", dest);
printf("\n");
printf("The second in source string : %s", src);
printf("\n");
strcat(dest,src);
printf("Concatenated strings : %s ", 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<string.h>
#include<stdio.h>
int main()
{
char dest[20] = "Hello";
char src[10] = "World";
printf("The value in dest string : %s", dest);
printf("\n");
printf("The second in src string : %s", src);
printf("\n");
int len1 = strlen(dest);
int len2 = strlen(src);
printf("Length of characters in dest string : %d \n", len1);
printf("Length of characters in src string : %d \n", len2);
for(int i=0;i<len2; i++)
{
dest[len1] = src[i];
len1 = len1 + 1 ;
}
dest[len1]='\0';
printf("Concatenated strings : %s ", 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