作业帮 > 综合 > 作业

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

来源:学生作业帮 编辑:灵鹊做题网作业帮 分类:综合作业 时间:2024/04/28 15:15:14
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 open\n");
exit(0);
}
gets(name);
fputs(str,fp);
flose(fp);
if((fp=fopen(name,"r"))==NULL)
{
printf("canfhhkjadf\n");
exit(0);
}
fgets(str,strlen(str)+1,fp);
printf("oiehjhsdhfkjdf\n");
puts(str);
fclose(fp);
}
1>d:\my documents\visual studio 2008\projects\们渴望你的\们渴望你的\了房间.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 files\vc\include\stdio.h(279) :参见“gets”的声明
1>d:\my documents\visual studio 2008\projects\们渴望你的\们渴望你的\了房间.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 files\vc\include\stdio.h(237) :参见“fopen”的声明
1>d:\my documents\visual studio 2008\projects\们渴望你的\们渴望你的\了房间.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 files\vc\include\stdio.h(279) :参见“gets”的声明
1>d:\my documents\visual studio 2008\projects\们渴望你的\们渴望你的\了房间.c(15) :warning C4013:“flose”未定义;假设外部返回 int
1>d:\my documents\visual studio 2008\projects\们渴望你的\们渴望你的\了房间.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 files\vc\include\stdio.h(237) :参见“fopen”的声明
1>d:\my documents\visual studio 2008\projects\们渴望你的\们渴望你的\了房间.c(21) :warning C4013:“strlen”未定义;假设外部返回 int
1>正在链接...
1>了房间.obj :error LNK2019:无法解析的外部符号 _flose,该符号在函数 _main 中被引用
1>d:\My Documents\Visual Studio 2008\Projects\们渴望你的\Debug\们渴望你的.exe :fatal error LNK1120:1 个无法解析的外部命令
c(7) :warning C4996:'gets':This function or variable may b v
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 open\n");
exit(0);
}
gets(name); /* 这里改成 fgets(name,sizeof(name),stdin); */
fputs(str,fp);
flose(fp); /* 这里写错了!应该是fclose(fp); */
if((fp=fopen(name,"r"))==NULL)
{
printf("canfhhkjadf\n");
exit(0);
}
fgets(str,strlen(str)+1,fp);
printf("oiehjhsdhfkjdf\n");
puts(str);
fclose(fp);
}