3条回答 默认 最新
北冥有鱼wyh 2019-05-17 08:23关注正确代码
#include "pch.h" #include<stdio.h> #include<stdlib.h> #include<string.h> int main() { char c[50] = { "People's Republic of " }; char str[] = { "China" }; strcat_s(c, str); printf("%s\n", c); system("pause"); return 0; }运行结果
错误总结
1、对于char c[50] = { "People's Republic of'\0'" };,字符串c并不需要写出'\0',因为系统编译时运行默认自动在字符串结尾处添加'\0';
2、strcat_s(c, str)默认返回类型是errno_t,你输出strcat_s(c, str)相对于输出errno_t类型的结果,由此出现上述错误结果;
3、未正确理解strcat_s(c, str)功能。其真正功能是将str连接到c的结尾处,故其结果是在c字符串中,而不是在返回值中。本回答被题主选为最佳回答 , 对您是否有帮助呢?评论 打赏 举报解决 2无用

