a3: letzte Addresse stimmt noch nicht

This commit is contained in:
Johannes Theiner 2018-11-08 11:05:35 +01:00
parent ebd099bef6
commit 528e68ed88
1 changed files with 15 additions and 6 deletions

View File

@ -1,7 +1,6 @@
#include "a3.h" #include "a3.h"
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <assert.h>
#include <memory.h> #include <memory.h>
void memdump(unsigned char *string) { void memdump(unsigned char *string) {
@ -36,8 +35,19 @@ void memdump(unsigned char *string) {
int memreplace(char *string, char cin, char cout, char **caddr) { int memreplace(char *string, char cin, char cout, char **caddr) {
//memctl int found = 0;
return 42; 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) { int main(int argc, char **argv) {
@ -61,12 +71,11 @@ int main(int argc, char **argv) {
strcpy((char *) copy, argv[1]); strcpy((char *) copy, argv[1]);
char **lastAddress = NULL; char **lastAddress = NULL;
int count = memreplace(argv[1], *argv[2], *argv[3], lastAddress); int count = memreplace(argv[1], *argv[2], *argv[3], lastAddress);
printf("Suchzeichen wurde %i mal gefunden und ersetzt\n", count); 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); memdump(copy);
free(copy); free(copy);