Code:
hex = (unsigned char *)malloc(0x4466446);
No need for casting in C
Undefined behavior
Code:
/*Clear memory allocation*/
hex = NULL;
printf("Memory cleared!\n");
Setting a pointer to NULL isn't clearing the memory. You have to call free().
Code:
printf("Start of memory block: %p\n", hex);
printf("End of memory block: %p\n", hex + 65536 - 1);
You have allocated 71722054 bytes of memory (0x4466446) thus hex + 65536 - 1 isn't the end of your memory block.
If you have "cleared the memory" before (option 2), you have lost any reference to the memory block and free() isn't able to free the block.
Code:
/*Store data*/
*hex = 0x0F;
*(hex+1) = 0x11;
*(hex+2) = 0xFF;
*(hex+3) = 0x1B;
*(hex+4) = 0x00;
*(hex+5) = 0xB6;
You hardcode the length of your data so there is no other way to determine the end than also hardcode the length into your for-loop:
Code:
for (x = 0; x < 6; x++){
printf("\nThe Value of hex %x is: %i\n",*(hex+x), *(hex+x));
printf("\nThe value of X is: %i\n", x);
getchar();
}
Bye, Andreas