歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> 關於Linux >> 顯示文件內容的腳本

顯示文件內容的腳本

日期:2017/3/1 16:56:56   编辑:關於Linux
顯示文件內容的腳本 C代碼 www.2cto.com #include <stdio.h> #include <fcntl.h> #include <malloc.h> #include <string.h> #include <unistd.h> #include <stdlib.h> int main(int argc,char *argv[]) { int fd,i=1,a,c,t; int tsize; char *buf; buf=malloc(sizeof(char)*256); if(argv[2]==NULL) c=1; else c=atoi(argv[2]); if(c<=0) c=1; for(a=1;a<=c;a++) { fd=open(argv[1],O_RDONLY); if(fd<0) { printf("Not find file!\n"); } i=1; t=1; while(i>0) { memset(buf,0,256); i=read(fd,buf,256); if((t%2)==0) usleep(20000); if((t%5)==0) usleep(800000); if((t%3)==0) usleep(500000); if((t%10)==0) usleep(1000000); usleep(500000); printf("%s",buf); t++; } printf("**********************************************************************\n"); sleep(2); close(fd); } return 0; }
Copyright © Linux教程網 All Rights Reserved