/* Program to show correct storage of floating data by binary i-o */ #include #include #include main() { float d, e; FILE *f; d = sqrt(2.0); f = fopen("tempfile.dat", "wb"); /* NB: "wb" means "write binary" */ fwrite(&d, sizeof(float), 1, f); /* Write from d, 1 item the size of a float to file f */ fclose(f); f = fopen("tempfile.dat", "rb"); /* NB: "rb" means "read binary" */ fread(&e, sizeof(float), 1, f); /* Read into e, 1 item the size of a float from file f */ fclose(f); printf("%f is ", d); if (d != e) { printf("NOT "); } printf("equal to %f\n", e); return 0; }