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

用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 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序