strcat in C Programming

The C Strcat function is one of the String functions used to join the user-specified string to the end of the existing one, and the resultant is stored in the first string we specified.

The basic syntax of the strcat in C Programming language is as shown below. The following function accepts the character array as parameter 1 & parameter 2. Next, it will concatenate or join the second string after the first using the built-in function strcat.

strcat(string1, string2);

Return Value: The C strcat Function will join two strings and store the data in the first argument (string1).

strcat in C Programming Example

The C strcat function is used to join two strings. This program will help you to understand the strcat (concatenation of two strings) with examples.

TIP: You must include the #include<string.h> header before using any string function.

// concatenate strings  
#include <stdio.h> 
#include<string.h>
int main()
{
   char str1[] = "Learn";
   char str2[] = " C Programming Language";
   char str3[] = " at tutorialgateway.org";
	
   strcat(str1, str2);		
   puts(str1);
   puts(str2);
 	
   strcat(str2, str3);
   puts(str2);
   puts(str3);	
	
   strcat(str3, " we provide free tutorials");
   puts(str3);
}
strcat in C Programming 1

Within this C program, First, we declared three character arrays, str1, str2, and str3, and by using the first three statements. Next, we assigned the text data (a group of characters) to each character array.

The following statement will join str2 to the end of str1, and the result will store in str1.

strcat(str1, str2);

The following C programming statement will join str3 to the end of str2, and the result will store in str2.

strcat(str2, str3);

Next, we used the text directly inside the function.

strcat(str3, " we provide free tutorials");