Question: Provided is a program called staticMemoryDump.c, which statically allocates memory for an array, fills it using scanf(), and then outputs each character of the array
Provided is a program called staticMemoryDump.c, which statically allocates memory for an array, fills it using scanf(), and then outputs each character of the array in columnar form: the address, the char in hex, and the char is ASCII form.
You will need to use that source code as 'the seed', and you are to modify it to dynamically allocate the same amount of memory, fill it in with the same characters, and the output the same information. Do not forget to deallocate the memory you've allocated earlier.
Modify the provided static memory code below to dynamic memory using c language not c++
staticMemoryDump.c:
#include
int main(void) {
char name[25];
char *ch;
printf("name: ");
scanf("%s", &name[0]);
ch = &name[0];
while (*ch != '\0') {
printf("%p\t0x%02x\t%c ", ch, *ch, *ch);
ch++;
}
printf("%p\t0x%02x\t%c ", ch, *ch, *ch);
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
