a3: Einrückung
This commit is contained in:
parent
19318517ca
commit
03014fb411
17
src/c/a3.c
17
src/c/a3.c
@ -11,17 +11,17 @@ void memdump(unsigned char *string) {
|
||||
char array[columns * rows];
|
||||
|
||||
for(int i = 0; i < rows; i++) {
|
||||
printf("0x%p\t", (void *) &string[i * columns]);
|
||||
printf("%p\t", (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] = '.';
|
||||
if(string[j] < 0x20 || string[j] > 0x7e) array[j] = '.';
|
||||
else array[j] = string[j];
|
||||
}
|
||||
printf(" ");
|
||||
|
||||
for (int j = i * columns; j < (i + 1) * columns; j++) {
|
||||
printf("%c", string[j]);
|
||||
printf("%c", array[j]);
|
||||
|
||||
}
|
||||
printf("\n");
|
||||
@ -50,17 +50,16 @@ int main(int argc, char **argv) {
|
||||
memdump((unsigned char *) argv[1]);
|
||||
|
||||
|
||||
printf("Laenge der Zeichenkette (inkl \\0): %i Byte(s)\n", (int) strlen(argv[1]));
|
||||
printf("Ersetzen: '%c' mit '%c'\n", *argv[2], *argv[3]);
|
||||
printf("\tLaenge der Zeichenkette (inkl \\0): %i Byte(s)\n", (int) strlen(argv[1]));
|
||||
printf("\tErsetzen: '%c' mit '%c'\n", *argv[2], *argv[3]);
|
||||
|
||||
unsigned char *copy = malloc(4 * 16 * sizeof(char));
|
||||
strcpy((char *) copy, argv[1]);
|
||||
|
||||
char test = 't';
|
||||
char *lastAddress = &test;
|
||||
char *lastAddress = NULL;
|
||||
int count = memreplace((char *) copy, *argv[2], *argv[3], &lastAddress);
|
||||
printf("Suchzeichen wurde %i mal gefunden und ersetzt\n", count);
|
||||
printf("zuletzt an Addresse 0x%p \n", (void *) lastAddress);
|
||||
printf("\tSuchzeichen wurde %i mal gefunden und ersetzt\n", count);
|
||||
printf("\tzuletzt an Addresse %p \n", (void *) lastAddress);
|
||||
memdump(copy);
|
||||
|
||||
free(copy);
|
||||
|
Loading…
Reference in New Issue
Block a user