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);