Using write and read system call. Following is an example:

blk.h:

#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h> struct data{
char s[];
int d1;
char c;
}; #define BLK_SIZE 25

writeb.c:

#include "blk.h"

int main(){
struct data *d= malloc(BLK_SIZE);
d->d1= ;
d->c= 'a';
strcpy(d->s, "first try.."); int fd= open("blk.dat", O_RDWR | O_CREAT | O_EXCL, S_IREAD | S_IWRITE);
write(fd, d, BLK_SIZE);
printf("writed!\n");
close(fd);
return ;
}

readb.c:

include "blk.h"

int main(){
int fd;
struct data *d;
fd= open("blk.dat", O_RDWR);
read(fd, d, BLK_SIZE);
printf("%d, %c, %s\n", d->d1, d->c, d->s);
close(fd);
return ;
}

how to write a struct to a file directly?的更多相关文章

  1. 简明python教程 --C++程序员的视角(八):标准库

    os模块 这个模块包含普遍的操作系统功能. 如果你希望你的程序能够与平台无关的话,这个模块是尤为重要的.一个例子就是使用os.sep可以取代操作系统特定的路径分割符. os.system() 执行li ...

  2. Non Lasting Storage File System、procfs、sysfs

    catalog . 引言 . proc文件系统 . 简单的文件系统 . sysfs 0. 引言 传统上,文件系统用于在块设备上持久存储数据,但也可以使用文件系统来组织.提供.交换并不存储在块设备上的信 ...

  3. file.go

        //    return int64(f.offset), errors.New("offset > file.size")     //}else {     // ...

  4. Downloading files from a server to client, using ASP.Net, when file size is too big for MemoryStream using Generic Handlers (ashx)

    Currently, I was trying to write an ASP.Net application that involved a user clicking a ASP.Net butt ...

  5. Even uploading a JPG file can lead to Cross-Site Content Hijacking (client-side attack)!

    Introduction: This post is going to introduce a new technique that has not been covered previously i ...

  6. HDFS relaxes a few POSIX requirements to enable streaming access to file system data

    https://hadoop.apache.org/docs/r2.7.2/hadoop-project-dist/hadoop-hdfs/HdfsDesign.html Introduction [ ...

  7. how browser handler file:/// link

    1. why browser can only open .txt file directly, pop up open or save dialog for others? 2. html cann ...

  8. iOS开发系列--Swift进阶

    概述 上一篇文章<iOS开发系列--Swift语言>中对Swift的语法特点以及它和C.ObjC等其他语言的用法区别进行了介绍.当然,这只是Swift的入门基础,但是仅仅了解这些对于使用S ...

  9. Usual tiny skills & solutions

    Ubuntu and Win10 - double OS 2016-02-21 Yesterday I helped my friend install Ubuntu (14.04 LTS) on h ...

随机推荐

  1. autoconfig操作小结

    1.添加maven配置在pom文件中 <profile>     <id>prod</id>     <properties>         < ...

  2. ERROR Worker: All masters are unresponsive! Giving up

    启动spark的时候发现,主节点(master)上的Master进程还在,子节点(Worker)上的Worker进程自动关闭. 在子节点上查询log发现: ERROR Worker: All mast ...

  3. 批量安装XP补丁的命令

    方法一: 新建一个bat文件,把这个文件和所有补丁文件放在同一个目录下,双击运行. BAT代码如下 @echo offfor %%i in (*.exe) do %%i /passive /nores ...

  4. 如何优化 App 的启动时间

    http://www.cocoachina.com/ios/20161102/17931.html App 运行理论 main() 执行前发生的事 Mach-O 格式 虚拟内存基础 Mach-O 二进 ...

  5. 8VC Venture Cup 2017 - Elimination Round

    传送门:http://codeforces.com/contest/755 A题题意是给你一个数字n,让你找到一个数字m,使得n*m+1为合数,范围比较小,直接线性筛出1e6的质数,然后暴力枚举一下就 ...

  6. ubuntu下百度云安装

    1.安装 在github上下载 .deb 安装包 下载地址 https://github.com/LiuLang/bcloud-packages 下载完成双击安装文件安装成功 2.解决验证码问题 (1 ...

  7. em,strong,b,i的区别

    文章来源: http://www.zhihu.com/question/19551271 默认样式: strong=b=粗体 em=i=斜体   HTML4.01: strong,em代表语义,从语义 ...

  8. UVa 10305 Ordering Tasks (例题 6-15)

    传送门: https://uva.onlinejudge.org/external/103/10305.pdf 拓扑排序(topological sort)简单题 自己代码的思路来自: ==>  ...

  9. java 导出excel(简单案例)

    public class Student { private int id; private String name; private int age; private Date birth; pub ...

  10. 单尺度二维离散小波分解dwt2

    clc,clear all,close all; load woman; [cA,cH,cV,cD]=dwt2(X,'haar');%单尺度二维离散小波分解.分解小波函数haar figure,ims ...