#include <stdio.h>
#include <string.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
int main(int argc,char* argv[])
{
if(argc != 2){
printf("Format should be:myCat filename/n");
}
int from_fd;
char buf[255];
from_fd = open("./argv[1]",O_RDONLY);
while(1){
int r = read(from_fd,buf,strlen(buf));
write(1,buf,strlen(buf));
if(r = 0){
break;
}
}
write(1,argv[1],strlen(argv[1]));
printf("/n");
return 0;
}
简易文件读取
本文介绍了一个简单的C语言程序,该程序用于从命令行接收文件名参数,并将文件内容输出到标准输出设备。程序使用了标准的文件操作API,如open、read和write等函数。
1811

被折叠的 条评论
为什么被折叠?



