#include <string.h>
char *strncat(char *dest, const char *src, size_t n);

功能:将src字符串前n个字符连接到dest的尾部,‘\0’也会追加过去
参数:

  • dest:目的字符串首地址
  • src:源字符首地址
  • n:指定需要追加字符串个数

返回值:

  • 成功:返回dest字符串的首地址
  • 失败:NULL

案例

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>

int main(void)
{
    char dest[100] = "hello";
    char src[] = "world";
    // 字符串有限追加
    strncat(dest, src, 3);
    printf("%s\n", dest);

    return 0;
}
strncat 使用案例:使用函数

相关文章:

  • 2022-12-23
  • 2021-08-21
  • 2022-12-23
  • 2021-12-20
  • 2021-12-19
  • 2021-09-18
  • 2022-01-02
  • 2022-12-23
猜你喜欢
  • 2022-01-01
  • 2022-12-23
  • 2021-11-02
  • 2022-12-23
  • 2022-12-23
  • 2022-01-08
  • 2022-12-23
相关资源
相似解决方案