#include <math.h>
#include <stdio.h>
int fun(char *fname )
{ FILE *fp; int i,n; float x;
if((fp=fopen(fname, "w"))==NULL) return 0;
for(i=1;i<=10;i++)
/**********found**********/
fprintf(fp,"%d %f\n",i,sqrt((double)i));
printf("\nSucceed!!\n");
/**********found**********/
fclose(fp);
printf("\nThe data in file :\n");
/**********found**********/
if((fp=fopen(fname,"r"))==NULL)
return 0;
fscanf(fp,"%d%f",&n,&x);
while(!feof(fp))
{ printf("%d %f\n",n,x); fscanf(fp,"%d%f",&n,&x); }
fclose(fp);
return 1;
}
void main()
{ char fname[]="myfile3.txt";
fun(fname);
}
将1~10和其平方根写到文本文件,再按顺序读出并显示在屏幕上
最新推荐文章于 2025-05-26 11:46:14 发布