a3: Kommentare hinzugefügt
This commit is contained in:
parent
03014fb411
commit
1ee921b000
23
src/c/a3.c
23
src/c/a3.c
|
@ -8,21 +8,22 @@ void memdump(unsigned char *string) {
|
|||
|
||||
int columns = 16;
|
||||
int rows = 4;
|
||||
char array[columns * rows];
|
||||
char symbols[columns * rows];
|
||||
|
||||
for(int i = 0; i < rows; i++) {
|
||||
printf("%p\t", (void *) &string[i * columns]);
|
||||
printf("%p\t", (void *) &string[i * columns]);//print address
|
||||
|
||||
for (int j = i * columns; j < (i + 1) * columns; j++) {
|
||||
printf("%02x ", string[j]);
|
||||
if(string[j] < 0x20 || string[j] > 0x7e) array[j] = '.';
|
||||
else array[j] = string[j];
|
||||
printf("%02x ", string[j]);//print char number
|
||||
if(string[j] < 0x20 || string[j] > 0x7e)//check for printable characters
|
||||
symbols[j] = '.';
|
||||
else symbols[j] = string[j];
|
||||
}
|
||||
printf(" ");
|
||||
|
||||
//print characters
|
||||
for (int j = i * columns; j < (i + 1) * columns; j++) {
|
||||
printf("%c", array[j]);
|
||||
|
||||
printf("%c", symbols[j]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
@ -32,10 +33,11 @@ void memdump(unsigned char *string) {
|
|||
int memreplace(char *string, char cin, char cout, char **caddr) {
|
||||
int found = 0;
|
||||
for (int i = 0; i < strlen(string); ++i) {
|
||||
//if char is to be replaced
|
||||
if(string[i] == cin) {
|
||||
string[i] = cout;//replace char
|
||||
found++;
|
||||
string[i] = cout;
|
||||
*caddr = &string[i];
|
||||
*caddr = &string[i];//setting last found address
|
||||
}
|
||||
}
|
||||
return found;
|
||||
|
@ -49,11 +51,10 @@ int main(int argc, char **argv) {
|
|||
|
||||
memdump((unsigned char *) argv[1]);
|
||||
|
||||
|
||||
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));
|
||||
unsigned char *copy = malloc(4 * 16 * sizeof(char));//allocate memory for all chars
|
||||
strcpy((char *) copy, argv[1]);
|
||||
|
||||
char *lastAddress = NULL;
|
||||
|
|
Loading…
Reference in New Issue