a3: ganz kleine Fixes
This commit is contained in:
parent
b9d89c1e85
commit
19318517ca
15
src/c/a3.c
15
src/c/a3.c
@ -1,27 +1,27 @@
|
||||
#include "a3.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <memory.h>
|
||||
#include <malloc.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\t\t00 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("%p ", (void *) &string[i * columns]);
|
||||
printf("0x%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", array[j]);
|
||||
printf("%c", string[j]);
|
||||
|
||||
}
|
||||
printf("\n");
|
||||
@ -50,7 +50,7 @@ int main(int argc, char **argv) {
|
||||
memdump((unsigned char *) argv[1]);
|
||||
|
||||
|
||||
printf("Laenge der Zeichenkette (inkl \\0): %i Bytes\n", (int) strlen(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]);
|
||||
|
||||
unsigned char *copy = malloc(4 * 16 * sizeof(char));
|
||||
@ -60,8 +60,7 @@ int main(int argc, char **argv) {
|
||||
char *lastAddress = &test;
|
||||
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 %p \n", lastAddress);
|
||||
printf("zuletzt an Addresse 0x%p \n", (void *) lastAddress);
|
||||
memdump(copy);
|
||||
|
||||
free(copy);
|
||||
|
Loading…
Reference in New Issue
Block a user