From 19318517ca4ef6fb9f339d3a7753eb2fe848995a Mon Sep 17 00:00:00 2001 From: Johannes Theiner Date: Wed, 14 Nov 2018 21:06:37 +0100 Subject: [PATCH] a3: ganz kleine Fixes --- src/c/a3.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/c/a3.c b/src/c/a3.c index 88296fa..93c11f8 100644 --- a/src/c/a3.c +++ b/src/c/a3.c @@ -1,27 +1,27 @@ #include "a3.h" -#include #include #include +#include void memdump(unsigned char *string) { - printf("ADDR 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 0123456789ABCDEF\n"); + printf("ADDR\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 array[columns * rows]; for(int i = 0; i < rows; i++) { - printf("%p ", (void *) &string[i * columns]); + printf("0x%p\t", (void *) &string[i * columns]); for (int j = i * columns; j < (i + 1) * columns; j++) { printf("%02x ", string[j]); - if(string[j] < 0x20 || string[j] > 0x7e) array[j] = '.'; + if(string[j] <= 0x20 || string[j] >= 0x7e) array[j] = '.'; else array[j] = string[j]; } printf(" "); for (int j = i * columns; j < (i + 1) * columns; j++) { - printf("%c", array[j]); + printf("%c", string[j]); } printf("\n"); @@ -50,7 +50,7 @@ int main(int argc, char **argv) { memdump((unsigned char *) argv[1]); - printf("Laenge der Zeichenkette (inkl \\0): %i Bytes\n", (int) strlen(argv[1])); + printf("Laenge der Zeichenkette (inkl \\0): %i Byte(s)\n", (int) strlen(argv[1])); printf("Ersetzen: '%c' mit '%c'\n", *argv[2], *argv[3]); unsigned char *copy = malloc(4 * 16 * sizeof(char)); @@ -60,8 +60,7 @@ int main(int argc, char **argv) { char *lastAddress = &test; int count = memreplace((char *) copy, *argv[2], *argv[3], &lastAddress); printf("Suchzeichen wurde %i mal gefunden und ersetzt\n", count); - //TODO: change type - printf("zuletzt an Addresse %p \n", lastAddress); + printf("zuletzt an Addresse 0x%p \n", (void *) lastAddress); memdump(copy); free(copy);