📄 rp2.c
字号:
/*This program realize the function that recive a filename from standard input device, * read the file and output the content by standard output device. * * you must compeletly realize by systemcall ,and can't use libery function and parameters by main! * * Kong Xiangzhen * class 33 * 03055078 * OCT 27th ,2006.*/ #include <unistd.h>#include <stdio.h>#include <sys/types.h>#include <fcntl.h>#include <sys/stat.h>#define max_read_size 2000#define max_filename 100int main(){ int fd,i_r,i_w; char buff[max_read_size]; char tip[100]="Give the file's name that you want to read:"; char readfilename[max_filename]; if((i_w=write(1,tip,100))<0) { perror("write tip error!"); exit(0); } if((i_r=read(0,readfilename,sizeof(readfilename)))<0) { perror("read filename error!"); exit(0); } readfilename[i_r-1]='\0'; if((fd=open(readfilename,O_RDONLY,0644))<0) { perror("open error!"); exit(0); } if((i_r=read(fd,buff,sizeof(buff)))<0) { perror("read error!"); exit(0); } if((i_w=write(1,buff,i_r))<0) { perror("write error!"); exit(0); } return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -