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
28
29
30
31
32
33
34
35
36
37
38
39
#include <stdio.h>
#include <stdlib.h>
#include "backwards_file.h"

//┌───────────────────────────────────────────────┐
//│ This was created in OFFICE HOURS on 3/29/2019.│
//└───────────────────────────────────────────────┘

int main(int argc, char* argv[]) {
    FileWrapper* file_wrapper = create_file_wrapper(filename);

    // Get and print the last line.
    unsigned char* line = read_line(file_wrapper);
    printf("%s", line);
    free(line);
    
    // Get and print the second to last line.
    line = read_line(file_wrapper);
    printf("%s", line);
    free(line);

    // Get and print the third to last line.
    line = read_line(file_wrapper);
    printf("%s", line);
    free(line);

    free_wrapper(file_wrapper);

    return EXIT_SUCCESS;
}

// TODO: Check if create_file_wrapper(…) and/or read_line(…) return NULL.
//
// As is, this would cause a segmentation fault if the file cannot be found or if it
// contains fewer than 3 lines.  This example is left simple for illustration purpose.
//
// TODO: Test -- This code was created as an example and has not been tested.

/* vim: set tabstop=4 shiftwidth=4 fileencoding=utf-8 noexpandtab: */

© Copyright 2019 Alexander J. Quinn         This content is protected and may not be shared, uploaded, or distributed.