How to read and write double value from binary file in C

1 Answer

0 votes
#include <stdio.h>

int main(void)
{
    const char* filename = "d:\\date.bin";

    double d1 = 627.9182;
    FILE* fp = fopen(filename, "wb");
    fwrite(&d1, sizeof d1, 1, fp);
    fclose(fp);

    fp = fopen(filename, "rb");
    double d2;
    fread(&d2, sizeof d2, 1, fp);
    printf("%lf\n", d2);
    fclose(fp);
}




/*
run:

627.918200

*/

 



answered Feb 3, 2023 by avibootz
edited Feb 3, 2023 by avibootz

Related questions

...