hello203 2021-12-22 12:03 采纳率: 73.3%
浏览 406
已结题

用VS编写的他显示fopen_s用于调用的参数太少是啥错误,代码如下,

#include<stdio.h>#include<string.h>#include<stdlib.h>#include<time.h>char n3[5];char n7[5];char n8[10];void easy(int j){ int a, n1, n2; int n4; char b; srand((unsigned int)time(0)); for (size_t i = 0; i < 2; i++) { a = rand(); int p = a % (10 - 0 + 1) + 1; if (i == 0) n1 = p; else n2 = p; sleep(1500); } srand((unsigned int)time(0)); n4 = rand(); if (n4 % 2 == 1) b = '+'; else b = '-'; n3[1] = n1; n3[2] = b; n3[3] = n2; n3[4] = '=';}void medium(int j){ int a, n1, n2; int n4; char b; int t; srand((unsigned int)time(0)); for (size_t i = 0; i < 2; i++) { a = rand(); int p = a % (100 - 0 + 1) + 1; if (i == 0) n1 = p; else n2 = p; sleep(1500); } srand((unsigned int)time(0)); n4 = rand(); t = n4 % 4; if (t == 1) b = '+'; else if (t == 2) b = '-'; else if (t == 3) b = ''; else b = '/'; if (b == '/' && n7[3] == 0) n7[3]++; n7[1] = n1; n7[2] = b; n7[3] = n2; n7[4] = '=';}void diffucult(int j){ int a, n1, n2; int n4; char b; int n10, n11; int t; srand((unsigned int)time(0)); for (size_t i = 0; i < 4; i++) { a = rand(); int p = a % (10 - 0 + 1) + 1; if (i == 0) n1 = p; else if (i == 1) n2 = p; else if (i == 2) n10 = p; else if (i == 3) n11 == p; sleep(1500); } srand((unsigned int)time(0)); n4 = rand(); t = n4 % 4; if (t == 1) b = '+'; else if (t == 2) b = '-'; else if (t == 3) b = ''; else b = '/'; if (b == '/' && n7[3] == 0) n7[3]++; n8[0] == n1; n8[2] == '/'; n8[3] == n2; n8[4] == 'b'; n8[5] == n3; n8[6] == '/'; n8[7] == n4; n8[9] == '=';}int main(){ int a, b; int j; int n1, n2; FILE* fp; if ((fp = fopen_s("easy.text", "w")) == NULL) { printf("打开失败"); exit(-1); } for (j = 0; j < 20; j++) { easy(j); fprintf(fp,"%s",n3); } fclose(fp); if ((fp = fopen_s("medium.text", "w")) == NULL) { printf("打开失败"); exit(-1); } for (j = 0; j < 20; j++) { medium(j); fprintf(fp, "%s", n7); } fclose(fp); for (j = 0; j < 20; j++) { easy(j); fprintf(fp,"%s",n3); } fclose(fp); if ((fp = fopen_s("difficult.text", "w")) == NULL) { printf("打开失败"); exit(-1); } for (j = 0; j < 20; j++) { difficult(j); fprintf(fp, "%s", n8); } fclose(fp);}

  • 写回答

3条回答 默认 最新

  • CSDN专家-sinJack 2021-12-22 12:06
    关注

    fopen_s的原型是errno_t fopen_s( FILE** pFile, const char *filename, const char *mode );
    第一个参数是填写fp,第二个参数是文件名,第三个参数是打开方式。

    fopen_s加上第一个参数。

    fopen_s("medium.text", "w")
    改为
    
    fopen_s(&fp,"medium.text", "w")
    

    其他地方同理修改。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 7月21日
  • 已采纳回答 7月13日
  • 创建了问题 12月22日

悬赏问题

  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据