strcat in C Programming

The C Strcat function is one of the String Function, used to join the user-specified string to the end of the existing string, and the resultant 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 string using the built-in String function strcat.

strcat(string1, string2);

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

strcat in C Programming Example

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

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

// strcat in C Programming to 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, str3, and by using the following statement we assigned a string data (a group of characters) to each character array

char str1[] = "Learn";
char str2[] = " C Programming Language";
char str3[] = " at tutorialgateway.org";

The following C strcat 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 string data directly inside the strcat function

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