开发者

replacing bytes in C data

I have the following code:

unsigned char* originaldata = (unsigned char*)malloc(50);
strcpy((char*)originalData,"12345       7");

unsigned char* replacingData = (unsigned char*)malloc(9);
strcpr((char*)replacingData,"11111111");

memset(replacingData,6,6);

Then, I want to replace the data from position 6 till end of originalData with replacingData.

H开发者_如何学Goow could i do this in C code?


memcpy(originalData+6, replacingData, strlen(originalData)-6)

Although, it should be noted that this makes the assumption that originalData is always greater than 6 characters long and that replacingData is longer than 6 characters shorter than originalData.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜