void FlushBuf(char** tmp, char* value, int len)
{
FlushBufMemory(tmp, len + 1);
strcpy(*tmp, value);
}
void FlushBufMemory(char** tmp, int len) {
free(*tmp);
*tmp = (char*)malloc(len);
memset(*tmp, 0, len);
}
Demo:
//提取值
int valueLen = posSepa - 2;
char thisValue[valueLen + 1] = {0};
memset(thisValue, 0, valueLen + 1);
strncpy(thisValue, buf + 2, valueLen);
thisValue[valueLen] = '\0';
FlushBuf(&serDict.dicKey, thisKey, keyLen);