open,write,read函数
2016-12-28 18:42
337 查看
1、写文件write函数:
#include <stdio.h>
//文件操作函数头文件
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
ssize_t write(int fd, const void *buf, size_t count);
–参数fd表示:使用open 函数打开文件之后返回的句柄
–参数*buf表示:写入的数据
–参数count表示:最多写入字节数
–返回值:出错-1,;其它数值表示实际写入的字节数
2、读文件read函数:
//标准输入输出头文件
#include <stdio.h>
//文件操作函数头文件
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#define MAX_SIZE 1000
ssize_t read(int fd,void *buf,size_t len);
–参数fd:使用open 函数打开文件之后返回的句柄
–参数*buf:读出的数据保存的位置
–参数len:每次最多读len 个字节
–返回值:错误返回-1,执行成功返回实际读取值
#include <stdio.h>
//文件操作函数头文件
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
ssize_t write(int fd, const void *buf, size_t count);
–参数fd表示:使用open 函数打开文件之后返回的句柄
–参数*buf表示:写入的数据
–参数count表示:最多写入字节数
–返回值:出错-1,;其它数值表示实际写入的字节数
2、读文件read函数:
//标准输入输出头文件
#include <stdio.h>
//文件操作函数头文件
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#define MAX_SIZE 1000
ssize_t read(int fd,void *buf,size_t len);
–参数fd:使用open 函数打开文件之后返回的句柄
–参数*buf:读出的数据保存的位置
–参数len:每次最多读len 个字节
–返回值:错误返回-1,执行成功返回实际读取值
相关文章推荐
- Linux centos 7下: 用 C 语言连接 MySQL数据库
- 13.OpenGL--显示列表
- 12.OpenGL--多边形偏移
- apache-php底层工作原理
- 用shell 脚本创建lfw的正负样本对
- Ubuntu下用apt安装Nginx和PHP
- date
- RHCE练习题 1. 配置SeLinux
- Openstack 实战讲解之-----------03-控制节点服务配置 推荐
- Tomcat version 7.0 only supports J2EE 1.2, 1.3, 1.4, and Java EE 5 and 6 Web modules
- linux下mysql忘记密码的通用处理(简单暴力)
- Linux 进程管理
- 【Linux】find 命令概述
- centos 7上nginx+uwsgi 性能调优
- apache和nginx
- Linux vi 文件编辑
- Openwebrtc
- linux初学<第二章习题一>用命令和正则表达式按照要求建立文件!
- Docker:集装箱式“运输”在软件上的实现
- Tomcat部署war包大小超出限制的大小