I am trying to do a simple program like this. There is an input, which is a wide-char message and i should copy only some substrings of this message to the output. In the example below, the output should be input+input[3..5]. So lets say for wcMessageIn='ABCDEFG' I should get wcMessageOut='DCDE'.
Can you please help me with the memcpy? In the real world, the messages will be long and I would be copying substrings of hundreds or thousands characters, so I would like to avoid doing it in a loop, char by char.
#define MSG_LENGTH 4096
static wchar_t *wcMessageIn;
static wchar_t *wcMessageOut;
int main(int argc, char *argv)
wcMessageIn = (wchar_t *)malloc(MSG_LENGTH * sizeof(wchar_t));
wcMessageOut = (wchar_t *)malloc(MSG_LENGTH * sizeof(wchar_t));
/* receive message and convert it to wcMessageIn using mbstowcs */
/* lMsgWCharLen = mbstowcs(wcMessageIn, cMessage, MSG_LENGTH); */
/* copy 4th character on input to 1st character on output - THIS WORKS*/
wcMessageOut = wcMessageIn;
/* append 3th to 5th character on input to output - THIS DOES NOT WORK */
memcpy(wcMessageOut + 1*sizeof(wchar_t), wcMessageIn + 2*sizeof(wchar_t), 3*sizeof(wchar_t));
/* do some cleanup here */