From 69ae65649357911b43430eb2c5b9ae653896253e Mon Sep 17 00:00:00 2001 From: Johannes Theiner Date: Fri, 9 Nov 2018 10:06:20 +0100 Subject: [PATCH] a3: kleine Tests --- src/c/a3.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/c/a3.c b/src/c/a3.c index 7b55bbb..1af6471 100644 --- a/src/c/a3.c +++ b/src/c/a3.c @@ -36,16 +36,17 @@ void memdump(unsigned char *string) { int memreplace(char *string, char cin, char cout, char **caddr) { int found = 0; + char *bla = NULL; for (int i = 0; i < strlen(string); ++i) { if(string[i] == cin) { found++; - string[i] = cout; + //TODO: fix pointer assignment //if(*caddr) free(caddr); - char *bla = &string[i]; - caddr = &bla; + bla = &string[i]; } + *caddr = bla; } return found; } @@ -72,7 +73,7 @@ int main(int argc, char **argv) { strcpy((char *) copy, argv[1]); char **lastAddress = NULL; - int count = memreplace(argv[1], *argv[2], *argv[3], lastAddress); + 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 0x%02x \n", (unsigned int) &lastAddress);