寰宇榛仁 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 铜与钢双金属板叠加在一起每种材料300mm长,18mm宽,4mm厚一端固定并加热至80℃,当加热端温度保持不变时另一端的稳态温度。ansys
  • ¥15 django5安装失败
  • ¥60 ios系统storm sniffer 写入http规则加密如何破解?
  • ¥15 Java与Hbase相关问题
  • ¥15 后缀 crn 游戏文件提取资源
  • ¥15 ANSYS分析简单钎焊问题
  • ¥20 bash代码推送不上去 git fetch origin master #失败了
  • ¥15 LOL外服加入了反作弊系统,现在游戏录像rofl文件离线都无法打开
  • ¥15 在centos7安装conda
  • ¥15 c#调用yolo3 dll文件获取的数据对不上