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

#include<stdio.h> #include<process.h> 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=fope... 展开
发布于2012-07-04 19:50 最佳答案
fclose写flose 
gets风险fgets.

见注释:

#include<stdio.h>
#include<process.h>
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);
}

为您推荐: