a3: letzte Addresse stimmt noch nicht
This commit is contained in:
parent
ebd099bef6
commit
528e68ed88
21
src/c/a3.c
21
src/c/a3.c
|
@ -1,7 +1,6 @@
|
|||
#include "a3.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include <memory.h>
|
||||
|
||||
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);
|
||||
|
|
Loading…
Reference in New Issue