fwrite单精度用fread双精度读取
时间: 2023-10-25 21:29:39 浏览: 95
![ZIP](https://csdnimg.cn/release/download/static_files/pc/images/minetype/ZIP.png)
基于C语言的高精度矩阵计算器.zip
可以使用以下方法将单精度浮点数使用`fwrite`写入文件,然后使用`fread`读取为双精度浮点数:
写入单精度浮点数:
```c
float value = 3.14;
FILE *file = fopen("data.bin", "wb");
fwrite(&value, sizeof(float), 1, file);
fclose(file);
```
读取双精度浮点数:
```c
double result;
FILE *file = fopen("data.bin", "rb");
fread(&result, sizeof(double), 1, file);
fclose(file);
```
在这个例子中,我们使用`fwrite`将单精度浮点数`value`写入名为"data.bin"的二进制文件。然后,使用`fread`从同一文件中读取一个双精度浮点数并存储在`result`变量中。请注意,读取时要使用双精度的`sizeof(double)`来指定要读取的字节数。
阅读全文
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![-](https://img-home.csdnimg.cn/images/20210720083327.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)