Linux文件编程综合(创建打开等)
来源:互联网 发布:dede模板下载站源码 编辑:程序博客网 时间:2024/06/15 09:56
include<sys/types.h>#include<sys/stat.h>#include<fcntl.h>#include<unistd.h>#include<stdio.h>#include<string.h>#include<stdlib.h>#include<errno.h>#define FLAGS O_RDWR#define MODE S_IRUSR|S_IWUSR|S_IXUSR//创建文件函数void write_creat(){const char *pathname;char pn1[20];int fd1;printf("input:");gets(pn1);pathname=pn1;if((fd1=creat(pathname,MODE))==-1){printf("error!\n");exit(1);}printf("OK!\n");printf("fd1=%d\n",fd1);return fd1;}//打开函数void write_open(){const char *pathname;char pn2[20];int fd2;printf("input:");gets(pn2);pathname=pn2;if((fd2=open(pathname,FLAGS,MODE))==-1){printf("error!\n");exit(1);}printf("OK!\n");printf("fd2=%d\n",fd2);return fd2;}//关闭函数void write_close(){const char *pathname;int fd3;char pn3[20];printf("input:");gets(pn3);pathname=pn3;if((fd3=close(pn3))==-1){printf("error!\n");exit(1);}printf("OK!\n");printf("fd3=%d\n",fd3);return fd3;}//读文件函数void write_read(){int fd4;const char *pathname;int count;int SIZE;char read_buf[SIZE];char pn4[20];printf("input:");gets(pn4);pathname=pn4;if((fd4=open(pathname,FLAGS,MODE))==-1){printf("error!\n");exit(1);}printf("OK!\n");printf("began!\n");printf("input size:");gets(SIZE);count=strlen(read_buf);if((fd4=read(fd4,read_buf,count))==-1){printf("error!\n");exit(1);}printf("OK!\n");printf("fd4=%d\n",fd4);return fd4;}//写函数void write_write(){int fd5;const char *pathname;int count;int SIZE;char write_buf[SIZE];char pn5[20];printf("input:");gets(pn5);pathname=pn5;if((fd5=open(pathname,FLAGS,MODE))==-1){printf("error!\n");exit(1);}printf("OK!\n");printf("began!\n");printf("input size:");gets(SIZE);count=strlen(write_buf);if((fd5=write(fd5,write_buf,count))==-1){printf("error!\n");exit(1);}}printf("OK!\n");printf("fd5=%d\n",fd5);return fd5;}//主函数void main(){write_creat();write_open();write_close();write_read();write_write();printf("done!!!");}
0 0
- Linux文件编程综合(创建打开等)
- 文件操作(创建,打开,读取,关闭等)
- linux C复习:文件操作(创建、打开、读写)
- linux c用open打开(创建)一个文件
- Linux下创建、打开、写入文件操作
- Linux下创建、打开、写入文件操作
- Linux系统编程-文件打开关闭
- Linux 用命令行打开doc pdf等文件
- linux内核空间 打开、读、写等文件操作实现
- Linux 用命令行打开doc pdf chm等文件
- Linux下时间编程(综合知识+综合编程):time,ctime,strftime,localtime,gmtime,gettimeofday
- Linux C编程学习笔记(2):open、creat、close函数及文件的创建、打开与关闭
- linux系统编程之文件与I/O(一):文件的打开关闭
- linux系统编程之文件与I/O(一):文件的打开关闭
- linux系统编程之文件与I/O(一):文件的打开关闭
- 创建并打开文件
- Linux文件编程之【系统调用】——综合实例:文件拷贝
- linux下C语言文件的创建打开和关闭
- ZKoss树的一个例子
- Leetcode Largest Rectangle in Histogram
- 缓冲区概念
- Animation之tween动画
- python中的装饰器Decorator用法
- Linux文件编程综合(创建打开等)
- C语言32个关键字
- 刚刚开始学习编程
- 全局变量,局部变量和形式参数
- [1194]:Beat the Spread!
- 浮点数的比较
- C++有子对象的派生类的构造函数
- iOS上传文件(图片)之AFNetworking 3.0上传文件上传图片
- 声明,定义,赋值,初始化的区别