Ok guys, here is the code working finally!!
Code:
#include <stdio.h>
main(){
FILE *fp1,*fp2;
float y;
fp1 = fopen("ain.txt", "rb");
fp2 = fopen("aout.txt","wb");
while(fread(&y,sizeof(y),1,fp1)==1)
fwrite(&y,sizeof(y),1,fp2);
fclose(fp1);
fclose(fp2);
}
Inputs like this were outputted exactly the same way (in aout.txt)
Code:
1 1.2 1.23 1.234 1.2345
2 2.3 2.34 2.345 2.3456
3 3.4 3.45 3.456 3.4567
4 4.5 4.56 4.567 4.5678
5 5.6 5.67 5.678 5.6789
6 6.7 6.78 6.789 6.79
....
Now i have the following trouble:
How do i get those numbers from aout.txt into the variables of structure elements? I tried with a little modification (code below), but it did not work.. I am getting random values. Any ideas, pls..!
Code:
#include <stdio.h>
main()
{
FILE *fp;
struct data {
int x1;
float x2;
float x3;
float x4;
} y[10];
fp1 = fopen("aout.txt","rb");
int i = 0;
while(fread(&y[i],sizeof(y[i]),1,fp)==1)
{printf("\n%d %f %f %f",y[i].x1,y[i].x2,y[i].x3,y[i].x4);
i++;
}
printf("\n");
fclose(fp);
}
Thanks
anand