C library functions -strncat()
C Standard Library - <string.h>
Description
C Library Functionschar *strncat(char *dest, const char *src, size_t n)holdsrcthe string pointed to is appended todestthe end of the string pointed to, untilnuntil the character length.
Declaration
Below is the declaration of the strncat() function.
char *strncat(char *dest, const char *src, size_t n)
Parameter
- destdest -- Points to the destination array, which contains a C string and is large enough to hold the appended string, including the additional null character.
- src-- the string to be appended.
- n-- the maximum number of characters to be appended.
Return Value
This function returns a pointer to the final destination string dest.
Example
The following example demonstrates the usage of the strncat() function.
#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 us compile and run the above program, which will produce the following result:
最终的目标字符串: |This is destinationThis is source|other extensions