您的位置:首页 > 移动开发

文件I/O-006.没有文件时 创建新的,若有则APPEND打开

2016-09-28 22:33 239 查看
/*
若没有文件,则创建新文件,若有文件,则APPEND打开
笔记 循环打开同一个文件,每次都是不同的文件描述符,每次都有一个文件表项,指向同一个V节点表项
*/
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
int main(int argc,char const *argv[])
{
int fd;
int i;
char tmp='a';
for(i=0;i<10;i++)
{
fd=open("test.txt",O_CREAT|O_RDWR|O_APPEND,0777);
printf("%d %d\n",i,fd);
write(fd,&tmp,1);
tmp++;
}
}
/*
./a.out
0 3
1 4
2 5
3 6
4 7
5 8
6 9
7 10
8 11
9 12
od -c test.txt
0000000   a   b   c   d   e   f   g   h   i   j
0000012
*/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐