level 1
shuiluzhou
楼主
请问以下问题(见18行)怎样样解决(©应为叉加园)?改为fopen_s不行,显示出错。
© C4996 'fopen': This function or variable may be unsafe. Consider using fopen s instead. To disable deprecation, use CRT SECURE NO WARNINGS. See online help for details.
// _4CCTWO.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#include "pch.h"
#include <iostream>
#define N 5
typedef struct
{
int num;
char name[10];
char tel[10];
} STYPE;
void check();
/**********found**********/
int fun(STYPE *std)
{
/**********found**********/
FILE * fp; int i;
if ((fp = fopen("myfile5.dat", "wb"))== NULL)
return(0);
printf("\nOutput data to file!\n");
for (i = 0;i < N;i++)
/**********found**********/
fwrite(&std[i],sizeof(STYPE),1, fp);
fclose(fp);
return(1);
}
int main()
{
STYPE s[10] = { {1,"aaaaa","111111"},{1,"bbbbb","222222"},{1,"ccccc","333333"},{1,"ddddd","444444"},{1,"eeeee","555555"} };
int k;
k = fun(s);
if (k == 1)
{
printf("Succeed!"); check();
}
else
printf("Fail!");
}
2018年10月12日 02点10分
1
© C4996 'fopen': This function or variable may be unsafe. Consider using fopen s instead. To disable deprecation, use CRT SECURE NO WARNINGS. See online help for details.
// _4CCTWO.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#include "pch.h"
#include <iostream>
#define N 5
typedef struct
{
int num;
char name[10];
char tel[10];
} STYPE;
void check();
/**********found**********/
int fun(STYPE *std)
{
/**********found**********/
FILE * fp; int i;
if ((fp = fopen("myfile5.dat", "wb"))== NULL)
return(0);
printf("\nOutput data to file!\n");
for (i = 0;i < N;i++)
/**********found**********/
fwrite(&std[i],sizeof(STYPE),1, fp);
fclose(fp);
return(1);
}
int main()
{
STYPE s[10] = { {1,"aaaaa","111111"},{1,"bbbbb","222222"},{1,"ccccc","333333"},{1,"ddddd","444444"},{1,"eeeee","555555"} };
int k;
k = fun(s);
if (k == 1)
{
printf("Succeed!"); check();
}
else
printf("Fail!");
}