Originally Posted by
lovesunset21
Thank you so much. One more question is how to convert an integer n to an unint64_t array of 8 elements. I tried it with memcpy:
unint64_t Data[8];
memcpy(&Data[0], &n, sizeof(Data))
And then, I tried to print the Data array
It displayed "Segmentation Fault".
Any suggestion? Thank you.
The problem is that memcpy will try to copy sizeof(...) bytes from src into dest. Clearly the seg fault is because you can't copy after the 4th byte (I am assuming 32-bit ints here) from n, so when memcpy tries to address the 5th byte you overstep your bounds and seg fault.
Try
Code:
memcpy(&Data[0], &n, sizeof(int));
Also, if you are getting "segmentation fault" rather than "access violation" that leads me to think you're not on Windows, meaning you have man pages. You can learn a lot a lot alot from man pages. Try
Type q to quit. Scroll with the arrow keys.