【C语言】【unix c】编写代码实现cat的功能

xiaoxiao2021-02-27  180

编写代码实现cat的功能,编译成可执行文件名为pcat(pcat.c) #include <stdio.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <unistd.h> int main(int argc, char *argv[]) { int fd; int r; char buf[128]; fd = open(argv[1], O_RDONLY); if(fd == -1) { perror("open"); return -1; } while((r = read(fd, buf, 128)) > 0) { write(STDOUT_FILENO, buf, r); } close(fd); return 0; }
转载请注明原文地址: https://www.6miu.com/read-13775.html

最新回复(0)