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> 
int main()
   char str1[] = "Learn";
   char str2[] = " C Programming Language";
   char str3[] = " at";
   strcat(str1, str2);		
   strcat(str2, str3);
   strcat(str3, " we provide free tutorials");
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");

About Suresh

Suresh is the founder of TutorialGateway and a freelance software developer. He specialized in Designing and Developing Windows and Web applications. The experience he gained in Programming and BI integration, and reporting tools translates into this blog. You can find him on Facebook or Twitter.