Originally Posted by smeezekitty
please use code tags next time.
Very good point. But please don't quote the entire point next time and please don't rewrite the OP's code without explaining anything nor fixing the bugs.
Originally Posted by hjc
I have an allocated memory called shared_memory and a struct called shared_data. i want to copy contents from struct shared_data to shared_memory using memcpy function. Then i want to print the contents from shared memory. can somebody help? in my actual code shared_memory is of size 4k but shared_data is of a few bytes. so I want to copy these few bytes into a larger memory. later i want to print the entire contents of the shared_memory.
All that is unclear enough that I can't tell you what to do even if I thought that was appropriate.
I can point out a few specific bugs in the code you posted:
I don't see any declaration for a
so that line shouldn't compile. What did you ntend it to do?
You shouldn't have that *
. malloc() returned a pointer. The out of memory case is when the pointer itself is zero, not when the memory pointed to is zero.
For the same reason, you don't want that &
You need to learn the concepts behind pointers, including why the & is required for x but incorrect for shared_memory.
Beyond that, there is plenty more wrong. But harder to explain since I don't know what you're actually trying to do.