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

int main(int argc, const char *argv[])
{
  FILE *file = fopen(argv[1], "r");
  if (file) {
    int current_position = ftell(file);
    int character;

    fseek(file, 0L, SEEK_END);

    current_position = ftell(file);
    printf("file size: %d\n", current_position);

    while(current_position >= 0) {
      fseek(file, --current_position, SEEK_SET);
      character = getc(file);
      putchar(character);
    }

    fclose(file);
    return 0;
  }
}