寰宇榛仁 2022-03-04 17:23 采纳率: 66.7%
浏览 11

C Primer Plus (第6版)中文版 P303中程序清单11.26 copy2.c程序,运行有问题

C Primer Plus (第6版)中文版 P303中程序清单11.26 copy2.c程序,运行有问题,麻烦各位,怎么修改才不会有错误

#include <stdio.h>
#include <string.h>
#define WORDS "beast"
#define SIZE 40

int main(void)
{
    const char* orig = WORDS;
    char copy[SIZE] = "Be the best that you can be.";
    char* ps;

    puts(orig);
    puts(copy);
    ps = strcpy_s(copy + 7, 50, orig);
    puts(copy);
    puts(ps);

    return 0;
}

img

  • 写回答

1条回答 默认 最新

  • 四海一叶秋 2022-03-04 19:11
    关注

    你确定是这样的代码?很多问题好吧。strcpy_s返回值是errno_t(int)类型,不能赋值给char*指针。
    你想要的代码可能是这样?

    #define _CRT_SECURE_NO_WARNINGS
    #include <stdio.h>
    #include <string.h>
    #define WORDS "beast"
    #define SIZE 40
    
    int main(void)
    {
        const char* orig = WORDS;
        char copy[SIZE] = "Be the best that you can be.";
        char* ps;
        puts(orig);
        puts(copy);
        ps = strcpy(copy + 7, orig);
        puts(copy);
        puts(ps);
        return 0;
    }
    
    
    
    评论

报告相同问题?

问题事件

  • 创建了问题 3月4日

悬赏问题

  • ¥15 征集Python提取PDF文字属性的代码
  • ¥15 有偿求苍穹外卖环境配置
  • ¥15 代码在keil5里变成了这样怎么办啊,文件图像也变了,
  • ¥20 Ue4.26打包win64bit报错,如何解决?(语言-c++)
  • ¥15 clousx6整点报时指令怎么写
  • ¥30 远程帮我安装软件及库文件
  • ¥15 关于#自动化#的问题:如何通过电脑控制多相机同步拍照或摄影(相机或者摄影模组数量大于60),并将所有采集的照片或视频以一定编码规则存放至规定电脑文件夹内
  • ¥20 深信服vpn-2050这台设备如何配置才能成功联网?
  • ¥15 Arduino的wifi连接,如何关闭低功耗模式?
  • ¥15 Android studio 无法定位adb是什么问题?