r305_dm/TP1/Exo5/exo5.c

37 lines
803 B
C
Raw Permalink Normal View History

2023-09-13 19:57:20 +02:00
#include<stdio.h>
#include<time.h>
#include<stdlib.h>
#include<string.h>
#include<assert.h>
void hexdump(void *ptr, size_t size) {
unsigned char *p = ptr;
unsigned char *end = p + size;
char ascii[17];
size_t i;
for (i = 0; i < 16; ++i) {
ascii[i] = '\0';
}
i = 0;
while (p != end) {
if (i % 16 == 0) {
if (i != 0) {
printf(" |%s|\n", ascii);
}
printf("%p ", p);
}
printf("%02X ", *p);
if (*p >= ' ' && *p <= '~') {
ascii[i % 16] = *p;
} else {
ascii[i % 16] = '.';
}
++p;
++i;
}
while (i % 16 != 0) {
printf(" ");
++i;
}
printf(" |%s|\n", ascii);
}