用C语言将一个浮点数写入文件,再将其从文件中读出,哪出错了?我建的文件名没错。希望高手解答啊。
#include<stdio.h>#include<stdlib.h>voidmain(){FILE*fp8,*fp9;floatfdata1=25.68,fdata2;...
#include<stdio.h>
#include<stdlib.h>
void main()
{
FILE *fp8,*fp9;
float fdata1=25.68,fdata2;
if((fp8=fopen("d:\\测试文件.txt","wb+"))==NULL)
{
printf("can not open the file.\n");
exit(1);
}
fwrite(&fdata1,sizeof(float),1,fp8);
fclose(fp8);
if((fp9=fopen("d:\\测试文件.txt","rb+"))==NULL);
{
printf("file cannot be opened\n");
exit(1);
}
fread(&fdata2,sizeof(float),1,fp9);
printf("fdata2=%.2f\n",fdata2);
fclose(fp9);
} 展开
#include<stdlib.h>
void main()
{
FILE *fp8,*fp9;
float fdata1=25.68,fdata2;
if((fp8=fopen("d:\\测试文件.txt","wb+"))==NULL)
{
printf("can not open the file.\n");
exit(1);
}
fwrite(&fdata1,sizeof(float),1,fp8);
fclose(fp8);
if((fp9=fopen("d:\\测试文件.txt","rb+"))==NULL);
{
printf("file cannot be opened\n");
exit(1);
}
fread(&fdata2,sizeof(float),1,fp9);
printf("fdata2=%.2f\n",fdata2);
fclose(fp9);
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询