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

收藏:0   阅读:76

C 库函数 - strncat()

描述

C 库函数 char *strncat(char *dest, const char *src, size_t n)src 所指向的字符串追加到 dest 所指向的字符串的结尾,直到 n 字符长度为止。

声明

下面是 strncat() 函数的声明。

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

参数

返回值

该函数返回一个指向最终的目标字符串 dest 的指针。

实例

下面的实例演示了 strncat() 函数的用法。

#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);
}

让我们编译并运行上面的程序,这将产生以下结果:

最终的目标字符串: |This is destinationThis is source|
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!