Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

C Library Function – strncat()

C Library Function - strncat()

C Standard Library - <string.h> C Standard Library -

Description

C Library Function **char *strncat(char dest, const char src, size_t n) Puts the src appends the string pointed to by dest the end of the string pointed to by , until n the character length is reached.

Declaration

Below is the declaration of the strncat() function.



char *strncat(char *dest, const char *src, size_t n)

Parameters

Return Value

This function returns a pointer to the final destination string dest.

Example

The following example demonstrates the use of the strncat() function.



#include 

#include 



int main ()

{

   char src[50], dest[50];



   strcpy(src,  "This is source");

   strcpy(dest, "This is destination");



   strncat(dest, src, 15);



   printf("最终的目标字符串: |%s|", dest);

   

   return(0);

}

Let's compile and run the above program, which will produce the following result:



最终的目标字符串: |This is destinationThis is source|

C Standard Library - <string.h> C Standard Library -