how to write a struct to a file directly?
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?的更多相关文章
- 简明python教程 --C++程序员的视角(八):标准库
os模块 这个模块包含普遍的操作系统功能. 如果你希望你的程序能够与平台无关的话,这个模块是尤为重要的.一个例子就是使用os.sep可以取代操作系统特定的路径分割符. os.system() 执行li ...
- Non Lasting Storage File System、procfs、sysfs
catalog . 引言 . proc文件系统 . 简单的文件系统 . sysfs 0. 引言 传统上,文件系统用于在块设备上持久存储数据,但也可以使用文件系统来组织.提供.交换并不存储在块设备上的信 ...
- file.go
// return int64(f.offset), errors.New("offset > file.size") //}else { // ...
- 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 ...
- 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 ...
- 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 [ ...
- 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 ...
- iOS开发系列--Swift进阶
概述 上一篇文章<iOS开发系列--Swift语言>中对Swift的语法特点以及它和C.ObjC等其他语言的用法区别进行了介绍.当然,这只是Swift的入门基础,但是仅仅了解这些对于使用S ...
- Usual tiny skills & solutions
Ubuntu and Win10 - double OS 2016-02-21 Yesterday I helped my friend install Ubuntu (14.04 LTS) on h ...
随机推荐
- Space Shooter
项目:https://pan.baidu.com/s/1jIDe2H4 using UnityEngine; using System.Collections; namespace VoidGame ...
- css3技巧属性之text-overflow
text-overflow:clip | ellipsis 默认值:clip 取值: clip: 当对象内文本溢出时不显示省略标记(...),而是将溢出的部分裁切掉. ellipsis: 当对象内文本 ...
- Unity3D 导出的apk进行混淆和加固防止反编译
前言: 对于辛辛苦苦完成的apk程序被人轻易的反编译了,那就得不偿失了,这篇文章就是解决Unity打包出来的apk进行代码加固和混淆. 准备资料: 1:Obfuscator.zip 作用是代码混淆, ...
- C#使用LitJson解析JSON(转)
JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.它基于JavaScript(Standard ECMA-262 3rd Edition - Decembe ...
- de4dot 脱壳工具
开源免费的一款工具 官方地址http://www.de4dot.com/ 很NB的工具,能脱大部分的壳 如下 Babel.NET CodeFort CodeVeil CodeWall CryptoOb ...
- 自定义viewpager的界面切换动画
核心操作: 1.创建一个类实现 android.support.v4.view.ViewPager.PageTransformer 根据 position 实现判断哪个界面进行界面切换动画 publi ...
- cursor:pointer 什么意思?
cursor规则是设定网页浏览时用户鼠标指针的样式,也就是鼠标的图形形状cursor:pointer设定鼠标的形状为一只伸出食指的手,这也是绝大多数浏览器里面鼠标停留在网页链接上方时候的样式另外可以选 ...
- js--学习方法之2-转
再说几点忠告 1,不要着急看一些复杂网页效果的代码,这样除了打击你自信心,什么也学不到.没达到一定的武功水平,割了小JJ也学不会葵花宝典的. 2,别急着加技术交流QQ群,加牛人QQ.如果你找张三丰交流 ...
- PyConChina2016 北京站 献给Python开发者
开源编程语言Python近年来在互联网.游戏.云计算.大数据.运维.企业软件等领域有非常多的应用.今天小编就为大家推荐一场Python开发者的盛会:PyConChina2016(北京)! PyCon大 ...
- PAT 团体程序设计天梯赛-练习集 L2-003. 月饼
月饼是中国人在中秋佳节时吃的一种传统食品,不同地区有许多不同风味的月饼.现给定所有种类月饼的库存量.总售价.以及市场的最大需求量,请你计算可以获得的最大收益是多少. 注意:销售时允许取出一部分库存.样 ...