1、malloc 分配内存,remalloc重新分配内存,能保存原来的内容
char* mem = (char*)malloc(sizeof(char)*12);
memset(mem,'/0',strlen(mem));
*(mem) = 'h';
*(mem+1) = 'e';
*(mem+2) = 'r';
*(mem+3) = 'e';
*(mem+4) = '1';
*(mem+5) = '2';
*(mem+6) = '3';
*(mem+7) = '4';
sprintf(tmp,"sizeofmem=%d,mem=%s",strlen(mem),mem);
AfxMessageBox(tmp);
mem = (char *) realloc (mem, 12 + 24);
sprintf(tmp,"sizeofmem=%d,mem=%s",strlen(mem),mem);
AfxMessageBox(tmp);
sprintf(tmp,"mem=%c",mem[5]);
AfxMessageBox(tmp);
delete mem;
2、按标记拆分字符串
char *testStr = "test is ok!";
CString str = testStr;//_T("ab ac dd PM");
TCHAR seps[] = _T(" ");
TCHAR* token = _tcstok(str.GetBuffer(str.GetLength()), seps );
while( token != NULL) {
AfxMessageBox(token);
token = _tcstok(NULL, seps);
}