[討論] strtok分解字串 二維陣列

看板C_and_CPP作者 (就是愛希爾)時間14年前 (2011/06/29 00:41), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/2 (看更多)
最近在看分解字串的功能時, 看到用來存每段字串都是用二維陣列去存的 想問一下,以下例子有可以改寫的地方嗎? 一定要用二維的方式去儲存嗎? 謝謝 int i = 0; char *tokenPtr; char *delim = "@"; char p[6][30]; char filename[50] = "@PID@VID@VER@OS@Audio"; tokenPtr = strtok(filename, delim); while(tokenPtr != NULL) { strcpy(p[i], tokenPtr); printf("p[%d] = %s\n", i, p[i]); i++; tokenPtr = strtok(NULL, delim); } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 122.116.219.143
文章代碼(AID): #1E2WGWnn (C_and_CPP)
文章代碼(AID): #1E2WGWnn (C_and_CPP)