STRNCAT() Function – C Program

STRNCAT() Function – C Program

Write a C Program for concatenates two string using STRNCAT Function.

STRNCATE() Function : – The STRNCAT used to concatenate some portion of second string at the end of first string.

The Syntax of STRNCAT() Function :

strncat(str1, str2, 5) – The first 5 character of string str2 is concatenated at the end of string str1.
strncat(str2, str2, 2) – The first 2 character of string str1 is concatenated at the end of string str2.

Example of STRNCAT() Function C Program

#include<stdio.h>
#include<string.h>
 
int main()
{
char str1[100], str2[100];
 
printf("Please, enter the first string = ");
gets(str1)
 
printf("\nPlease, enter the second string = ");
gets(str2)
 
strncat(str1, str2, 4);
printf("\nThe concatenate string is = %s",str1);
 
return 0;
}

The output of STRNCAT() Function C Program is :

Please, enter the first string = Meera
Please, enter the second string = Academy

The concatenate string is = MeeraAcad

 

Author: Meera Academy

Leave a Reply

Your email address will not be published. Required fields are marked *