#include<sys/types.h> #include<sys/stat.h> #include<fcntl.h> #include<unistd.h> #include<errno.h>

#include<stdio.h> #include<string.h>

#define BUF_SIZE 30

int main(int argc, char* argv[]) { char buf[BUF_SIZE]; int len=0; int fd=-1;

if(argc != 2){ printf('wrong parameters '); return -1; }

fd = open(argv[1], O_RDONLY);

if(fd == -1){ printf('error in open file'); printf('the error is: %s ', strerror(errno)); return -1; }else{ //printf('open file success '); while((len=read(fd, buf, BUF_SIZE))!=0){ write(STDOUT_FILENO, buf, len); } } if(fd>0){ close(fd); } return 0; }

C语言文件读取代码错误修正 - 修复 open 函数参数

原文地址: https://www.cveoy.top/t/topic/nFMO 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录