博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
linux 对虚拟地址读写,linux下c通过虚拟地址映射读写文件的代码
阅读量:6913 次
发布时间:2019-06-27

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

在代码过程中中,把开发过程中比较好的一些代码片段记录起来,如下的代码内容是关于 linux下c通过虚拟地址映射读写文件的代码,应该对小伙伴有些好处。

#include

#include

#include

#include

#include

#include

#include

struct stu

{

char name[20];

int age;

float score;

};

main()

{

int fd;

struct stat st;

int size;

int count;

struct stu record;

memset(&record,0,sizeof(struct stu));

fd=open("newstu.dat",O_RDWR|O_CREAT|O_EXCL,0666);

if(fd==-1)

{

fd=open("newstu.dat",O_RDWR);

if(fd==-1) printf("::%mn"),exit(-1);

}

fstat(fd,&st);

count=size/sizeof(struct stu);

s=mmap(0,size+sizeof(struct stu),

PROT_READ|PROT_WRITE,

MAP_SHARED,fd,0);

printf("输入姓名:");

scanf("%s",s[count].name);

printf("输入年龄:");

scanf("%s",&(s[count].age));

printf("输入分数:");

scanf("%f",&(s[count].score));

int i;

for(i=0;i

{

printf("%s,%d,%.2fn",s[i].name,s[i].age,s[i].score);

}

munmap(s,size+sizeof(struct stu));

close(fd);

}

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

你可能感兴趣的文章
Android 获取文件大小
查看>>
linux删除或隐藏命令历史记录history
查看>>
java.lang.OutOfMemoryError: Java heap space
查看>>
认证 (authentication) 和授权 (authorization) 的区别
查看>>
Linux查看磁盘空间大小命令
查看>>
计算机软件著作权查询网址
查看>>
一起谈.NET技术,.Net4.0 Parallel编程(四)Task 上
查看>>
自定义Status Bar的基本方法
查看>>
react动画难写?试试react版transformjs
查看>>
Chrome(12)中使用getComputedStyle获取透明度(opacity)返回字符串不同于其它浏览器...
查看>>
【汉字乱码】IE下GET形式传递汉字。
查看>>
SmartImageView
查看>>
《FineUI秘密花园》在线阅读与完整PDF版
查看>>
android 混淆相关 proguard
查看>>
net.sf.json.JSONException: There is a cycle in the hierarchy!错误解决方案
查看>>
android TDD平台插入双卡时,查看允许返回发送报告的选项,去掉勾选,不起作用...
查看>>
2013年8月第2个周结
查看>>
(转)C的代码是如何变成程序的
查看>>
Udp SocketAsyncEventArgs SocketAsyncDataHandler
查看>>
音频处理平台
查看>>