//  Test fgetc on x86-64 and on ARMv8.
//  2019-10-10
#include <stdio.h>
#define BUFSIZE 100

int main(int argc, char **argv)
{
    if (argc < 2) {
        fprintf(stderr, "usage: %s <input-file>\n", argv[0]);
        return 1;
    }
    char buffer[BUFSIZE];
    int nlines = 0;
    FILE *handle = fopen(argv[1], "r");
    while ( NULL != fgets(buffer, BUFSIZE, handle) )
        printf("%2d %s", ++nlines, buffer); // No newline in format string!
    printf("\n#--------\n");

    rewind(handle);

    char c;
    int nchars = 0;
    while ( EOF != (c = fgetc(handle)) )
        printf("%2d %#02x %c\n", ++nchars, c, c);

    fclose(handle);

    return 0;
}