a3: jetzt ist wirklich nur noch die letze Adresse falsch
This commit is contained in:
parent
69ae656493
commit
eebb2f998c
27
src/c/a3.c
27
src/c/a3.c
@ -4,15 +4,15 @@
|
||||
#include <memory.h>
|
||||
|
||||
void memdump(unsigned char *string) {
|
||||
printf("ADDR 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 0123456789ABCDEF\n");
|
||||
printf("ADDR 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 0123456789ABCDEF\n");
|
||||
|
||||
int columns = 16;
|
||||
int rows = 4;
|
||||
char array[columns * rows];
|
||||
|
||||
|
||||
for(int i = 0; i < rows; i++) {
|
||||
printf("0x%02x ", string[i]);
|
||||
printf("%p ", (void *) &string[i * columns]);
|
||||
|
||||
for (int j = i * columns; j < (i + 1) * columns; j++) {
|
||||
printf("%02x ", string[j]);
|
||||
if(string[j] < 0x20 || string[j] > 0x7e) array[j] = '.';
|
||||
@ -24,29 +24,19 @@ void memdump(unsigned char *string) {
|
||||
printf("%c", array[j]);
|
||||
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
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++;
|
||||
|
||||
//TODO: fix pointer assignment
|
||||
//if(*caddr) free(caddr);
|
||||
bla = &string[i];
|
||||
|
||||
string[i] = cout;
|
||||
*caddr = &string[i];
|
||||
}
|
||||
*caddr = bla;
|
||||
}
|
||||
return found;
|
||||
}
|
||||
@ -69,14 +59,13 @@ int main(int argc, char **argv) {
|
||||
printf("Ersetzen: '%c' mit '%c'\n", *argv[2], *argv[3]);
|
||||
|
||||
unsigned char *copy = malloc(4 * 16 * sizeof(char));
|
||||
|
||||
strcpy((char *) copy, argv[1]);
|
||||
|
||||
char **lastAddress = NULL;
|
||||
int count = memreplace((char *) *copy, *argv[2], *argv[3], lastAddress);
|
||||
char *lastAddress = NULL;
|
||||
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);
|
||||
printf("zuletzt an Addresse %p \n", *lastAddress);
|
||||
memdump(copy);
|
||||
|
||||
free(copy);
|
||||
|
Loading…
Reference in New Issue
Block a user