下面的代码有错误请修改它:#includesystypesh#includesysstath#includefcntlh#includeunistdh#includeerrnoh#includestdioh#includestringh#define BUF_SIZE 30int mainint argc char argv	char bufBUF_SIZE;	int len=0;	int fd= 错误已修改,正确代码如下:

#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\n"); return -1; }

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

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

下面的代码有错误请修改它:#includesystypesh#includesysstath#includefcntlh#includeunistdh#includeerrnoh#includestdioh#includestringh#define BUF_SIZE 30int mainint argc char argv	char bufBUF_SIZE;	int len=0;	int fd=

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

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