I,m quite new to C and I was wondering the following:
I have this large buffer in which I wish to store some data. One of the things I would like to store in this buffer is the address of a pointer instead of the value, like following example:
Memory addresses are 4 bytes on my system, so I would like my block_buffer to contain "000015XXXX" where XXXX is the memory address of buffer.Code:char size = "000015"; char* buffer = (char*) malloc(15 * sizeof(char)); sprintf(buffer, "Lots of text..."); int buffer_size = 6 + sizeof(char*); char* block_buffer = (char*) malloc(buffer_size * sizeof(char));
Any idea how i do this?
And afterwards, when I split the block_buffer back up into size and address, how can i convert that address back to a char* containing the original "Lots of text..." data?
If someone could explain to my if this is possible or not, or what would be the better approach, that would be a great help.
Thanks in advance.