Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdint.h>
- #include <stdlib.h>
- #define NR 16
- int main(int argc, char **argv) {
- if (argc < 2) {
- fprintf(stderr, "args error!\n");
- exit(-1);
- }
- FILE *file = fopen(argv[1], "rb");
- if (file == NULL) {
- perror("opening error");
- exit(-1);
- }
- while (!feof(file)) {
- uint8_t buffer[NR] = {};
- printf("%08lX: ", ftell(file));
- fread(buffer, sizeof(*buffer), NR, file);
- for (int i = 0; i < NR; i++) {
- printf("%02X ", buffer[i]);
- }
- putchar('|');
- for (int i = 0; i < NR; i++) {
- if (buffer[i] >= 32) {
- putchar(buffer[i]);
- } else {
- putchar('.');
- }
- }
- puts("|");
- }
- if (fclose(file) == EOF) {
- perror(NULL);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement