本帖最后由 chenhahacjl 于 2021-10-28 16:51 编辑
#include <stdio.h>
#include <io.h>
int main()
{
FILE* file = fopen(".\\y.oth", "wb");
if (file == NULL)
{
printf("File open failed!\n");
return -1;
}
int wDate = 2021;
float wValue = -500;
fwrite(&wDate, 4, 1, file);
fwrite(&wValue, 4, 1, file);
fclose(file);
file = fopen(".\\y.oth", "rb");
if (file == NULL)
{
printf("File open failed!\n");
return -2;
}
int rDate;
float rValue;
fread(&rDate, 4, 1, file);
printf("Date = %d\n", rDate);
fread(&rValue, 4, 1, file);
printf("Value = %f\n", rValue);
fclose(file);
return 0;
}
|