Ajout de l'exo 5 sur le README
This commit is contained in:
@@ -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
37
Exo5/exo5.c
Normal 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);
|
||||
}
|
||||
Reference in New Issue
Block a user