From 8dce0c854b88b3a8cb5b98f30cc4f5bfdcf21ad5 Mon Sep 17 00:00:00 2001 From: Johannes Theiner Date: Thu, 15 Nov 2018 11:03:14 +0100 Subject: [PATCH] a3: Sollte jetzt mod 16 sein --- src/c/a3.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/c/a3.c b/src/c/a3.c index bec5ab4..424aa8a 100644 --- a/src/c/a3.c +++ b/src/c/a3.c @@ -2,17 +2,28 @@ #include #include #include +#include void memdump(unsigned char *string) { - printf("ADDR\t\t00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 0123456789ABCDEF\n"); + printf("ADDR\t\t\t00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 0123456789ABCDEF\n"); int columns = 16; int rows = 4; char symbols[columns * rows]; + if((long) string % 16 != 0) { + string = string - ((long) string % 16); + } + + for(int i = 0; i < rows; i++) { printf("%p\t", (void *) &string[i * columns]);//print address + if((long) string % 16 != 0) { + printf("oh nein, kein mod 16"); + } + + for (int j = i * columns; j < (i + 1) * columns; j++) { printf("%02x ", string[j]);//print char number if(string[j] < 0x20 || string[j] > 0x7e)//check for printable characters