// File Dump
#include <stdlib.h>
#include <stdio.h>

int main()
{
    FILE *fp;
    FILE *op;
    char filename[13];
    char oput[] = "output.txt";
    char buffer[81];
    int ndx;
    int i;
    int n;

    printf("Enter a file name: ");
    gets(filename);

    if ((fp = fopen(filename, "r")) == NULL) // Unable to find file
    {
        printf("\nCould not open %s\n", filename);
        system("PAUSE");
        exit(1);
    }

    if ((op = fopen(oput, "w")) == NULL) // Unable to find file
    {
        printf("\nCould not write %s\n", oput);
        system("PAUSE");
        exit(1);
    }

    while ((n=fread(buffer, 1, 81, fp)) > 0)
    {
        ndx = 0;
        while (ndx < n)
        {
            fprintf(op, "\n");
            for (i=0; i<8; ++i)
                fprintf(op, "%2X ", buffer[ndx+i]);
            fprintf(op, " | ");
            for (i=0; i<8; ++i)
                fprintf(op, "%c ", buffer[ndx+i]);
            ndx += 8;
        }
        for (i=0; i<81; ++i)
            buffer[i] = 0;
    }

    printf("\n\n");
    system("PAUSE");
    fclose(fp);
    return 0;
}
