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
.
精彩评论