Latest web development tutorials

C library functions - strncat ()

C standard library - <string.h> C standard library - <string.h>

description

C library functionschar * strncat (char * dest, const char * src, size_t n) pointed to the srcstring appended to the end of the string pointed to bydest,up untilncharacters in length.

statement

Here is () statement strncat function.

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

parameter

  • dest - to the target array, which contains a C string, and the string is sufficient to accommodate the additional post, including additional null character.
  • src - string to append.
  • n - maximum number of characters to append.

return value

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

Examples

The following example demonstrates strncat () function is used.

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

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 result in the following:

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

C standard library - <string.h> C standard library - <string.h>