From 1ee921b000549c54c4aa07e553cd78ab0cc1c124 Mon Sep 17 00:00:00 2001 From: Johannes Theiner Date: Thu, 15 Nov 2018 10:29:17 +0100 Subject: [PATCH 1/5] =?UTF-8?q?a3:=20Kommentare=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/c/a3.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/c/a3.c b/src/c/a3.c index 21f9b09..c7db7f9 100644 --- a/src/c/a3.c +++ b/src/c/a3.c @@ -8,21 +8,22 @@ void memdump(unsigned char *string) { int columns = 16; int rows = 4; - char array[columns * rows]; + char symbols[columns * rows]; for(int i = 0; i < rows; i++) { - printf("%p\t", (void *) &string[i * columns]); + printf("%p\t", (void *) &string[i * columns]);//print address for (int j = i * columns; j < (i + 1) * columns; j++) { - printf("%02x ", string[j]); - if(string[j] < 0x20 || string[j] > 0x7e) array[j] = '.'; - else array[j] = string[j]; + printf("%02x ", string[j]);//print char number + if(string[j] < 0x20 || string[j] > 0x7e)//check for printable characters + symbols[j] = '.'; + else symbols[j] = string[j]; } printf(" "); + //print characters for (int j = i * columns; j < (i + 1) * columns; j++) { - printf("%c", array[j]); - + printf("%c", symbols[j]); } printf("\n"); } @@ -32,10 +33,11 @@ void memdump(unsigned char *string) { int memreplace(char *string, char cin, char cout, char **caddr) { int found = 0; for (int i = 0; i < strlen(string); ++i) { + //if char is to be replaced if(string[i] == cin) { + string[i] = cout;//replace char found++; - string[i] = cout; - *caddr = &string[i]; + *caddr = &string[i];//setting last found address } } return found; @@ -49,11 +51,10 @@ int main(int argc, char **argv) { memdump((unsigned char *) argv[1]); - printf("\tLaenge der Zeichenkette (inkl \\0): %i Byte(s)\n", (int) strlen(argv[1])); printf("\tErsetzen: '%c' mit '%c'\n", *argv[2], *argv[3]); - unsigned char *copy = malloc(4 * 16 * sizeof(char)); + unsigned char *copy = malloc(4 * 16 * sizeof(char));//allocate memory for all chars strcpy((char *) copy, argv[1]); char *lastAddress = NULL; From d3cd764826a65e2a192f9b2c6d70f2b17bf9bb39 Mon Sep 17 00:00:00 2001 From: Johannes Theiner Date: Thu, 15 Nov 2018 10:35:22 +0100 Subject: [PATCH 2/5] a3: test --- src/c/a3.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/c/a3.c b/src/c/a3.c index c7db7f9..bec5ab4 100644 --- a/src/c/a3.c +++ b/src/c/a3.c @@ -49,7 +49,7 @@ int main(int argc, char **argv) { return -1; } - memdump((unsigned char *) argv[1]); + memdump((unsigned char *) argv[0]); printf("\tLaenge der Zeichenkette (inkl \\0): %i Byte(s)\n", (int) strlen(argv[1])); printf("\tErsetzen: '%c' mit '%c'\n", *argv[2], *argv[3]); From 8dce0c854b88b3a8cb5b98f30cc4f5bfdcf21ad5 Mon Sep 17 00:00:00 2001 From: Johannes Theiner Date: Thu, 15 Nov 2018 11:03:14 +0100 Subject: [PATCH 3/5] 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 From 0c6b5867c85f636ab9cbf4a21c0e4271ec40b02a Mon Sep 17 00:00:00 2001 From: Johannes Theiner Date: Thu, 15 Nov 2018 11:04:17 +0100 Subject: [PATCH 4/5] =?UTF-8?q?a3:=20Einr=C3=BCckung?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/c/a3.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/c/a3.c b/src/c/a3.c index 424aa8a..c575ef4 100644 --- a/src/c/a3.c +++ b/src/c/a3.c @@ -5,7 +5,7 @@ #include void memdump(unsigned char *string) { - printf("ADDR\t\t\t00 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; From 71646c46ab94e65768fb8297249000f2a26ea7e5 Mon Sep 17 00:00:00 2001 From: Johannes Theiner Date: Thu, 15 Nov 2018 11:14:39 +0100 Subject: [PATCH 5/5] a3: Anzahl Zeichen korrigiert --- src/c/a3.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/c/a3.c b/src/c/a3.c index c575ef4..9ec395a 100644 --- a/src/c/a3.c +++ b/src/c/a3.c @@ -62,7 +62,7 @@ int main(int argc, char **argv) { memdump((unsigned char *) argv[0]); - printf("\tLaenge der Zeichenkette (inkl \\0): %i Byte(s)\n", (int) strlen(argv[1])); + printf("\tLaenge der Zeichenkette (inkl \\0): %i Byte(s)\n", (int) strlen(argv[1]) +1); printf("\tErsetzen: '%c' mit '%c'\n", *argv[2], *argv[3]); unsigned char *copy = malloc(4 * 16 * sizeof(char));//allocate memory for all chars