c(7) :warning C4996:'gets':This function or variable may b v

游戏2022-10-04 11:39:541条回答

c(7) :warning C4996:'gets':This function or variable may b vc2008
#include
#include
main()
{
FILE *fp;
char str[81],name[10];
gets(name);
if((fp=fopen(name,"w"))==NULL)
{
printf("can not openn");
exit(0);
}
gets(name);
fputs(str,fp);
flose(fp);
if((fp=fopen(name,"r"))==NULL)
{
printf("canfhhkjadfn");
exit(0);
}
fgets(str,strlen(str)+1,fp);
printf("oiehjhsdhfkjdfn");
puts(str);
fclose(fp);
}
1>d:my documentsvisual studio 2008projects们渴望你的们渴望你的了房间.c(7) :warning C4996:'gets':This function or variable may be unsafe.Consider using gets_s instead.To disable deprecation,use _CRT_SECURE_NO_WARNINGS.See online help for details.
1> d:program filesvcincludestdio.h(279) :参见“gets”的声明
1>d:my documentsvisual studio 2008projects们渴望你的们渴望你的了房间.c(8) :warning 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.
1> d:program filesvcincludestdio.h(237) :参见“fopen”的声明
1>d:my documentsvisual studio 2008projects们渴望你的们渴望你的了房间.c(13) :warning C4996:'gets':This function or variable may be unsafe.Consider using gets_s instead.To disable deprecation,use _CRT_SECURE_NO_WARNINGS.See online help for details.
1> d:program filesvcincludestdio.h(279) :参见“gets”的声明
1>d:my documentsvisual studio 2008projects们渴望你的们渴望你的了房间.c(15) :warning C4013:“flose”未定义;假设外部返回 int
1>d:my documentsvisual studio 2008projects们渴望你的们渴望你的了房间.c(16) :warning 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.
1> d:program filesvcincludestdio.h(237) :参见“fopen”的声明
1>d:my documentsvisual studio 2008projects们渴望你的们渴望你的了房间.c(21) :warning C4013:“strlen”未定义;假设外部返回 int
1>正在链接...
1>了房间.obj :error LNK2019:无法解析的外部符号 _flose,该符号在函数 _main 中被引用
1>d:My DocumentsVisual Studio 2008Projects们渴望你的Debug们渴望你的.exe :fatal error LNK1120:1 个无法解析的外部命令

已提交,审核后显示!提交回复

共1条回复
城外倩影 共回答了14个问题 | 采纳率92.9%
fclose写成flose了!
gets有溢出风险,可改成fgets.
改法见注释:
#include
#include
main()
{
FILE *fp;
char str[81],name[10];
gets(name);
if((fp=fopen(name,"w"))==NULL)
{
printf("can not openn");
exit(0);
}
gets(name); /* 这里改成 fgets(name,sizeof(name),stdin); */
fputs(str,fp);
flose(fp); /* 这里写错了!应该是fclose(fp); */
if((fp=fopen(name,"r"))==NULL)
{
printf("canfhhkjadfn");
exit(0);
}
fgets(str,strlen(str)+1,fp);
printf("oiehjhsdhfkjdfn");
puts(str);
fclose(fp);
}
1年前

相关推荐