Home >>C String functions >C strncat() function

C strncat() function

C strncat() function

C Strncat() function is used to concatenate portion of one string at the end of another string.

Syntax:
Strcat(str2,str1,4)

Note:- Here first 4 characters of str1 is append at the end of str2.

Parameters:-

It takes 2 strings as parameter.

Return type:-

It returns modified string.

Example-1

#include <stdio.h>
#include <string.h>
int main( )
{
   char source[ ] = " helloc" ;
   char target[ ]= "C function" ;
   printf ( "\nSource string = %s", source ) ;
   printf ( "\nTarget string = %s", target ) ;
   strncat ( target, source, 5 ) ;
   printf ( "\nTarget string after strncat( ) = %s", target ) ;
}

Output:
source string=helloc
Target string=c function
Target string after strncat()=c function hell

No Sidebar ads