#include <stdio.h>
int write() {
FILE* file = NULL;
if (fopen_s(&file, "data.bin", "wb") != 0 || file == NULL) {
perror("Error opening file");
return 0;
}
float number = 3.14f; // Example float value
fwrite(&number, sizeof(float), 1, file); // Write the float to the file
fclose(file); // Close the file
return 1;
}
int read() {
FILE* file = NULL;
if (fopen_s(&file, "data.bin", "rb") != 0 || file == NULL) {
perror("Error opening file");
return 0;
}
float number = 0.0f;
fread(&number, sizeof(float), 1, file); // Read the float from the file
printf("Read float: %f\n", number); // Print the float value
fclose(file); // Close the file
return 1;
}
int main() {
if (write() == 1) {
read();
}
return 0;
}
/*
run
Read float: 3.140000
*/