UncleCoder.com

UncleCoder.com

Free programming examples and instructions

C program to study 'strcat()' function

C program for how to concatenate or join two strings using ‘strcat()’

by Krishna viswambharan


Posted on 28 Sep 2017 Category: C Views: 184

Edited on 14 Jan 2018


 

C program to study 'strcat()' function

In this article, we will see another string function.  Here we will see how to concatenate or join two strings using ‘strcat()’ function  This string function is defined in the <string.h> header file

strcat( ) function in C language concatenates two given strings. Synatx for strcat() is given as follows

char * strcat ( char * destination, const char * source );

for Example:
strcat ( str2, str1 ); – str1 is concatenated at the end of str2.
strcat ( str1, str2 ); – str2 is concatenated at the end of str1.

In the below program, the source string and the destination strings are concatenated using the string function strcat(). C code for the program is written as below.

#include <stdio.h>
#include <string.h>
#include <conio.h>
 
void main()
{
   char source[100], destination[100];
 
   printf("Enter input string1 :");
   gets(source);

   printf("Enter input string2 :");
   gets(destination);

 
   strcpy(destination, source);
 
   printf(“string after concatenation :%s”,source);
   getch();
}

output



Leave a Comment:


Advertisement