summaryrefslogtreecommitdiff
path: root/tailf.c
blob: 389e6a0c9196b928ae7fbf3a877420613ecc5c68 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <stdio.h>

int main(int argc,char *argv[]) {
 short in;
 FILE *fp;
 if(argc>1) {
  if(!(fp=fopen(argv[1],"r"))) {
   printf("file not found.\n");
   return 1;
  }
  while(1) {
   if((in=fgetc(fp)) == -1) {
    if(feof(fp)) {
     clearerr(fp);
    } else {
     printf("unknown error from fgetc()");
     return 2;
    }
   } else {
    printf("%c",in);
    fflush(stdout);
   }
  }
 } else {
  printf("usage: tailf filename\n");
 }
}