Skip to main content

Concatenating two strings in C with Function strcat

Concatenating means joining two strings for example first and last name.

strcat function belongs to string.h header file.

syntax for strcat function is char *strcat(char *stringOne, const char *stringTwo);

Below is code or example for strcat function.


//Program Name: strcat function example in c

#include <stdio.h>
#include <string.h>

int main () {
   char stringOne[50], stringTwo[50];

    printf ("\n\tEnter first String\t");
    scanf("%s",stringOne);
    printf("\n\tEnter Second String\t");
    scanf("%s",stringTwo);
    
    strcat(stringOne,stringTwo);
    
    printf("\nHere is concatenated string after using stcat function\n\n %s",stringOne);

   return(0);
}

Output



	Enter first String	Learning

	Enter Second String	-C


Here is concatenated string after using stcat function

 Learning-C