I am writing a code in C performing hexdump in both text and binary files. My output in text files are correct but when I tried performing hexdump in a binary file, I got garbages. I would like to ask for your help if which part of my code is wrong and how should I correct my mistakes. Thanks.
#include <stdio.h>
#define OFFSET 16
main(int argc, char const *argv[]) 
{
    FILE *fp;
    char buff[OFFSET];
    int read;
    int address = 0;
    int i;
    if (argc != 2){
        exit(0);
    }
    fp = fopen(argv[1], "rb");
    while ((read = fread(buff, 1, sizeof buff, fp)) > 0){
        printf("%08x ", address);
        address += OFFSET;
        //print hex values 
        for (i = 0; i < OFFSET; i++){
            if(i >= read){
                buff[i] = 0;
            }
            if(buff[i] >= 33 && buff[i] <= 255 || buff[i] != 00){
                printf("%02x ", buff[i]);
            }
            if(buff[i] == 00){
                printf("   ");
            }
        }
        //print ascii values
        for (i = 0; i < OFFSET; i++) {
            printf("%c", (buff[i] >= 33 && buff[i] <= 255 ? buff[i] : ' '));
        }
        printf("\n");
    }
    fclose(fp);
}
 
    