博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
c/c++二进制读写
阅读量:2352 次
发布时间:2019-05-10

本文共 753 字,大约阅读时间需要 2 分钟。

(1) Write file

#include <stdio.h>

#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[])
{
    FILE        *fp;
    double      temperature[10];
    double      *temp;
    int         i = 0;
    fp = fopen("temperature_data", "w");
    
    for (i = 0; i < 10; i++)
    {   
        temperature[i] = i;
    }   
    temp = temperature;
    for (i = 0; i < 10; i++)
    {   
        fwrite(temp, sizeof(double), 1, fp);
        temp = temp + 1;
    }   
//    fwrite(temperature, sizeof(double), 10, fp);

    fclose(fp);

(2) Read file

#include <stdio.h>

#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[])
{
    FILE        *fp;
    double      temp[1];
    int         i = 0;
    fp = fopen("temperature_data", "r");
    printf("The data in temperature is: \n");
    while(fread(temp, sizeof(double), 1, fp))
    {   
        printf("temperature[%d] is: %f\n", i, temp[0]);
        i++;
    }   
    fclose(fp);
}

转载地址:http://wlrvb.baihongyu.com/

你可能感兴趣的文章
IDE配置jvm参数
查看>>
内存溢出
查看>>
Spring Cloud 声明式服务调用 Feign
查看>>
IDEA安装插件
查看>>
我要学ASP.NET MVC 3.0(十): MVC 3.0 使用 Forms身份验证
查看>>
我要学ASP.NET MVC 3.0(十四): MVC 3.0 实例系列之创建数据表格
查看>>
我要学ASP.NET MVC 3.0(十五): MVC 3.0 实例系列之表格的排序
查看>>
VS2010的智能提示没有了的可能原因
查看>>
HTTP触发Jenkins参数化构建(CORS Plugin)
查看>>
ubuntu12.04--子进程 已安装 post-installation 脚本 返回了错误号 1
查看>>
系统--电脑开机一声长响
查看>>
系统--A disk read error occurred Press Ctrl+Alt+d...
查看>>
Some projects cannot be imported because they a...
查看>>
ubuntu-android--make: *** [out/host/linux-x86/o...
查看>>
原子变量与synchronized详细解释
查看>>
java.lang.OutOfMemoryError: PermGen space及其解决方法
查看>>
如何让ajaxfileupload.js支持IE9,IE10,并可以传递多个参数?
查看>>
highcharts扩展tooltip提示异步信息
查看>>
activiti--History 历史配置
查看>>
activiti--部署bpmn/bar文件详解
查看>>