初接触文件的读写,写了一个如下的小测试程序,输入数据是对的,可读入的数据却不对,还请大家帮忙
看下哪里写错了!
#include "stdio.h"
#include "fstream.h"
#define SIZE 2
struct data
{
double x;
double y;
double z;
}pos[SIZE],save[SIZE];
void main()
{
int i;
FILE *fop,*fip;
pos[0].x=3.0;
pos[0].y=58.34922;
pos[0].z=1.7;
pos[1].x=55.0;
pos[1].y=25.78;
pos[1].z=28.0;
if((fop=fopen("1.txt","w"))==NULL)
{
printf("can not open this file\n");
return;
}
for(i=0;i<SIZE;i++)
fprintf(fop,"%f\n",pos[i].x);
if((fip=fopen("1.txt","r"))==NULL)
{
printf("can not open file\n");
return;
}
for(i=0;i<SIZE;i++)
{
fscanf(fip,"%f",&save[i].x);
printf("%f\n",save[i].x);
}
}