看板 C_and_CPP 關於我們 聯絡資訊
改成這樣可能比較親切。 char* strtok2(char *pbuf, const char *pdelims, char **ppremain = NULL) { char *ptoken = strtok(pbuf, pdelims); if(ptoken && ppremain) { *ppremain = ptoken + strlen(ptoken) + 1; } return ptoken; } int _tmain(int argc, _TCHAR* argv[]) { char szString[256] = "aa bb cc ddd eee"; char *premain = NULL; char *ptoken = strtok2(szString, " ", &premain); do{ printf("toekn=%s ,remainder=%s\n", ptoken, premain); }while(ptoken =strtok2(NULL, " ", &premain)); return 0; } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.121.139.15