ok so i am trying to make a program in which the user can input 5 values then , these values are to be stored in a binary file.
Then I have to read the stored value from the binary file.
However , i keep getting a random number totally unrelated to the inputs.
here's my code please disregard the printf function it's just for testing the output.Also , note that i am only using data[].l and not the whole structure as a test .
Code:#include <stdio.h> #include <math.h> #define N 100 // number of points #define TRUE 1 #define FALSE 0 #define EPSILON 1e-10 #define BINFILE "file.bin" typedef struct { double l; // starting time double c; // ending time double v; // velocity double td; // time double pc; // altitude } INFO; int main() { INFO data[5]; int i=0; int flag = FALSE; int ans; FILE *fp; while(i < 5 && flag==FALSE) { printf("Please enter the value for L:\n"); scanf("%lf",&data[i].l); printf("Please enter the value for C:\n"); scanf("%lf",&data[i].c); printf("Please enter the value for the battery voltage:\n"); scanf("%lf",&data[i].v); printf("Please enter the value for the dissipation time td:\n "); scanf("%lf",&data[i].td); printf("Please enter the value for the percentage of the "); printf("\n original charge pc to reach within td\n"); scanf("%lf",&data[i].pc); i = i+1; printf("do you want to 1. enter a new set of values(max 5) and save these values\n"); printf("or 2.choose a saved set of values\n"); scanf("%d",&ans); if(ans==1) { fp = fopen(BINFILE, "wb"); fwrite(&data[i].l, sizeof(double), 1, fp); fclose(fp); } else { flag = TRUE; fp=fopen(BINFILE, "rb"); fread(&data[5].l,sizeof(double),1,fp); fclose(fp); } } printf("%lf",data[5].l); }