- Read函数说明
- Read函数使用
Read函数说明
名字:
read - read from a file descriptor
简介:
#include <unistd.h>
ssize_t read(int fd, void *buf, size_t count);
描述:
参数:
fd:文件句柄
*buf:读出的数据保存的位置
count:每次读取的长度
sszie_t:出错-1,成功返回读取到的内容
Read函数使用
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
int main(){
int fd;
char str[] = "hello xiao gui";
char rd[1024];
if(fd<open("/home/hello",O_CREAT|ORDWR,0777)<0){
}else{
write(fd,str,strlen(str));
while(read(fd,rd,1024)!=-1){
printf("%s\n",rd);
}
}
return 0;
}