
1、dst 内存空间大小=目标字符串长度+原始字符串场地+‘\0’。
2、使用sizeof函数获取内存空间大小,strlen函数获取字符串长度。
即获取内存空间大小和查字符串长度。
实例
#include"stdafx.h"
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include"windows.h"
//errorC4996:'strcat':Thisfunctionorvariablemaybeunsafe.Considerusingstrcat_sinstead.Todisabledeprecation,use_CRT_SECURE_NO_WARNINGS.Seeonlinehelpfordetails.
#pragmawarning(disable:4996)
voidmain()
{
charsrc[1024]={"C/C++教程-strcat_s函数"};
chardst[1024]={"www.codersrc.com"};
//注意:strcat_s第二个参数的计算,该参数是拼接后的字符串大小,并非原字符串大小或者目标字符串大小
intlen=strlen(src)+strlen(dst)+1;
printf("strcat_s之前dst:%s\n",dst);//
strcat_s(dst,len,src);
printf("strcat_s之后dst:%s\n",dst);//
system("pause");
}
输出结果:
strcat_s之前dst:www.codersrc.com
strcat_s之后dst:www.codersrc.comC/C++教程-strcat_s函数
请按任意键继续...
以上就是c语言strcat_s函数的原理,希望对大家有所帮助。更多C语言学习指路:C语言教程
原文来自:https://www.py.cn© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
    



















































 
        

暂无评论内容