Code:
while(1)
{
fread(&voltage,sizeof(double),1,ifp); //reading binary file into temporary variables
fread(¤t,sizeof(double),1,ifp);
fread(&diameter,sizeof(double),1,ifp);
if (diameter < 0.00000009)
{
//vertexnum = i;
//for(i=0; i<vertexnum; i++)
// {
//printf("%lf %10.29f %10.14f\n", out[i].voltage, out[i].current, out[i].diameter);
//}
test = 1;
break;
}
fprintf(volt1, "%lf\n", voltage);//printing out the values into the corresponding files
fprintf(amp1, "%10.29f\n", current);
fprintf(diam1, "%10.14f\n", diameter);
if(i ==39)
{
fprintf(volt1, "%lf\n", voltage);//printing out the values into the corresponding files
fprintf(amp1, "%10.29f\n", current);
fprintf(diam1, "%10.14f\n", diameter);
}
fread(&voltage,sizeof(double),1,ifp); //reading binary file into temporary variables
fread(¤t,sizeof(double),1,ifp);
fread(&diameter,sizeof(double),1,ifp);
fprintf(volt2, "%lf\n", voltage);//printing out the values into the corresponding files
fprintf(amp2, "%10.29f\n", current);
fprintf(diam2, "%10.14f\n", diameter);
if(i ==39)
{
fprintf(volt2, "%lf\n", voltage);//printing out the values into the corresponding files
fprintf(amp2, "%10.29f\n", current);
fprintf(diam2, "%10.14f\n", diameter);
}
i++;
//printf("%lf %10.29f %10.14f\n", out[i].voltage, out[i].current, out[i].diameter); //print to screen for verification
}
where ifp is the file pointer to the file being read, whereas volt1, volt2, amp1, amp2, diam1 and diam 2 are the file being written on. on i =39, a new point is being written to the file. I am not given the number of lines in the binary file, and I have attempted to break the loop by establishing an if loop that said if diameter < 0.00000009, the loop would break. This was solely based on my hypothesis that when its the end of file, the diameter is zero (i know it wouldn't, but its a form of a desparate move). Apparently it will loop on the last line of the data, but since some of the data repeats too so I can't based on it to end the loop either.