strncat

头文件:#inclue <string.h>

strncat()用于将n个字符追加到字符串的结尾,其原型为:
char * strncat(char *dest, const char *src, size_t n);

【参数说明】dest为目标字符串,src为源字符串,n为要追加的字符的数目。

strncat()将会从字符串src的开头拷贝n 个字符到dest字符串尾部,dest要有足够的空间来容纳要拷贝的字符串。如果n大于字符串src的长度,那么仅将src全部追加到dest的尾部。

strncat()会将dest字符串最后的'\0'覆盖掉,字符追加完成后,再追加'\0'。

【返回值】返回字符串dest。

【程序示例】字符串追加示例。
      
      
  1. #include<stdio.h>
  2. #include<string.h>
  3. int main(){
  4. char url[100] = "http://see.xidian.edu.cn";
  5. char path[30] = "/cpp/u/biaozhunku/";
  6. strncat(url, path, 1000); // 1000远远超过path的长度
  7. printf("%s\n", url);
  8. return 0;
  9. }
#include<stdio.h>
#include<string.h>

int main(){
    char url[100] = "http://see.xidian.edu.cn";
    char path[30] = "/cpp/u/biaozhunku/";
    strncat(url, path, 1000);  // 1000远远超过path的长度
    printf("%s\n", url);
    return  0;
}
运行结果:
http://see.xidian.edu.cn/cpp/u/biaozhunku/

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值