diff --git a/src/c/a3.c b/src/c/a3.c index 1f43a2b..7b55bbb 100644 --- a/src/c/a3.c +++ b/src/c/a3.c @@ -1,7 +1,6 @@ #include "a3.h" #include #include -#include #include void memdump(unsigned char *string) { @@ -36,8 +35,19 @@ void memdump(unsigned char *string) { int memreplace(char *string, char cin, char cout, char **caddr) { - //memctl - return 42; + int found = 0; + 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; + + } + } + return found; } int main(int argc, char **argv) { @@ -61,12 +71,11 @@ int main(int argc, char **argv) { strcpy((char *) copy, argv[1]); - char **lastAddress = NULL; int count = memreplace(argv[1], *argv[2], *argv[3], lastAddress); - printf("Suchzeichen wurde %i mal gefunden und ersetzt\n", count); - printf("zuletzt an Addresse 0x%lx \n", (unsigned long) (&lastAddress)); + //TODO: change type + printf("zuletzt an Addresse 0x%02x \n", (unsigned int) &lastAddress); memdump(copy); free(copy);