strcat(): String Concatenation in C Programming
String handling function strcat()
is used to concatenate two strings. Concatenation is the process of merging content of one string to another string. Function strcat(str1, str2)
concatenates content of string str2
after content of string str1
.
strcat() Syntax
strcat( string1, string2);
strcat() Example
#include<stdio.h>
#include<string.h>
int main()
{
char str1[50], str2[50];
printf("Enter first string:\n");
gets(str1);
printf("Enter second string:\n");
gets(str2);
strcat(str1,str2);
printf("Concatenated string is: %s", str1);
return 0;
}
strcat() Program Output
Enter first string:
Ram↲
Enter second String:
Shyam↲
Concatenated string is: RamShyam
Note: ↲ indicates ENTER is pressed.