diff options
| author | mo khan <mo@mokhan.ca> | 2015-12-29 10:25:17 -0700 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2015-12-29 10:25:17 -0700 |
| commit | 228c8513cf9830746e87b280f6f7890a351be4a3 (patch) | |
| tree | 745db66534210984616b83595f5221c9c0d07edd | |
| parent | 54685bfefd4000db0802192cefd4b987c9aa37f9 (diff) | |
start to implement tail.
| -rw-r--r-- | head.c | 2 | ||||
| -rw-r--r-- | tail.c | 24 |
2 files changed, 25 insertions, 1 deletions
@@ -23,7 +23,7 @@ int main(int argc, char *argv[]) FILE *file = fopen(argv[0], "r"); if (file) { - int character; + int character; while( (character = getc(file)) != EOF ) { putchar(character); @@ -0,0 +1,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; + } +} |
