AnsweredAssumed Answered

memcpy() in Codewarrior EWL

Question asked by Cory schwarzmiller on May 21, 2013
Latest reply on May 22, 2013 by Cory schwarzmiller

Hello all, I have a question regaarding the standard function in cstring.h called memcpy. My issue is that this function should be of the form:

 

void *memcpy(void *str1, const void *str2, size_t n);


When I try to call it in the form:

unsigned int dst[10];

unsigned int src[100];


memcpy(&dst[4], &src[9], 5);


it only copies 1 byte, because that is the length of "5".  I want it to copy 5 bytes. I tried casting the constant 5 to type "size_t":


memcpy(&dst[4], &src[9], ((size_t)5));


This also didn't work.


The way it does work, (although not the way i intended) is:


memcpy(&dst[0], &src[9], sizeof(dst));


How do I use a integer constant or variable in the quantity of bytes field!?

PS: I am using a Coldfire MCF52259.


Thank You,


Cory

Outcomes