Implement the a program that works like "tail".
Utilisateur anonyme
// Error checking omitted. // Assume the file fits in 4k bytes. #define NUM 10 // number of last lines to print. #define BUF_SIZE 0x1000 int main(int argc, char **argv) { assert(argc > 1); char buf[BUF_SIZE]; FILE *fp = fopen(argv[1], "r"); fseek(fp, 0, SEEK_END); int len = ftell(fp); rewind(fp); int read = fread(buf, sizeof buf - 1, 1, fp); buf[read] = 0; for (int i = 0; i < NUM; ++i) { char *found = strrchr(buf, '\n'); printf("%s\n", found+1); *found = 0; } fclose(fp); }