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 40 41 42 43 44 | #include <stdio.h>
#include <stdlib.h>
#include "backwards_file.h"
//┌───────────────────────────────────────────────┐
//│ This was created in OFFICE HOURS on 3/28/2019.│
//└───────────────────────────────────────────────┘
int main(int argc, char* argv[]) {
if(argc != 2) {
fprintf(stderr, "Usage: tac FILENAME\n");
return EXIT_FAILURE;
}
char* filename = argv[1];
FileWrapper* file_wrapper = create_file_wrapper(filename);
while(true) {
unsigned char* line = read_line(file_wrapper);
// If there are no more lines (or if there was an error), then quit.
if(line == NULL) {
break;
}
// Print the line. Notice no newline because it probably ended with a newline.
printf("%s", line);
// Just in case last line of file doesn't end in a '\n' (RARE)
if(line[strlen(line)] != '\n') {
printf("\n");
}
free(line);
}
free_wrapper(file_wrapper);
return EXIT_SUCCESS;
}
// 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.