Use sizeof to get the size of the data type
Fix the wrong data type
Replace the memcpy operation to the data cast