?? tail.c
字號:
/* Tail.C John Tal Based on Unix tail command but not fully implemented here */
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
struct tails{
char *inptr; /* data read from file */
int next; /* which tail[] member is next, numeric array index */
};
main(argc,argv)
int argc;
char **argv;
{
int lines,i,n,head,oldi,pass;
FILE *fp;
struct tails tail[25];
char buffer[255];
printf("tail, pc-dos version by john tal, 09/1988\n");
if(argc == 2)
lines = 20;
else{
printf("usage: tail filename");
return(1);
}
for(i = 0; i < lines; i++)
tail[i].inptr = malloc(255);
i = 0;
head = 0; /* initial head of circular buffer */
n = 255; /* max bytes to read into each buffer */
pass = 1; /* passes through internal buffers */
if((fp = fopen(argv[1],"r")) != NULL){
while(fgets(buffer,n,fp) != NULL){
oldi = i; /* remember */
i++; /* next slot */
if(i == lines){
i = 0; /* reset to beginning of buffers */
pass++; /* another pass */
}
if(pass != 1)
head = tail[i].next; /* new head */
tail[oldi].next = i; /* connect last to this one */
tail[i].next = -1; /* this one is new tail */
strcpy(tail[i].inptr,buffer); /* get data */
}
/* head = i; */ /* final head */
fclose(fp);
i = head;
while(i != -1){
printf("%s",tail[i].inptr);
i = tail[i].next;
}
/* free-up malloc'd stuff */
for(i = 0; i < lines; i++)
free(tail[i].inptr);
}
else{
printf("error: could not open file %s\n",argv[1]);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -