Ajout de l'exo 5 sur le README

This commit is contained in:
2023-09-13 19:57:20 +02:00
parent 7c9425c9d7
commit 598495d9f0
3 changed files with 73 additions and 1 deletions

View File

@@ -51,5 +51,18 @@ int main()
ex5.x=62;ex5.y=63;ex5.z=64;ex5.w=65;
// appelez hexdump pour chaque variable
hexdump(a, sizeof(a));
hexdump(c, sizeof(c));
hexdump(&ex1, sizeof(ex1));
hexdump(&ex2, sizeof(ex2));
hexdump(&ex3, sizeof(ex3));
hexdump(&ex4, sizeof(ex4));
hexdump(&ex5, sizeof(ex5));
hexdump(&x, sizeof(x));
hexdump(&y, sizeof(y));
hexdump(&z, sizeof(z));
hexdump(&w, sizeof(w));
return 0;
}

37
Exo5/exo5.c Normal file
View File

@@ -0,0 +1,37 @@
#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);
}