作者HILL33LOVE (就是愛希爾)
看板C_and_CPP
標題[討論] strtok分解字串 二維陣列
時間Wed Jun 29 00:41:02 2011
最近在看分解字串的功能時,
看到用來存每段字串都是用二維陣列去存的
想問一下,以下例子有可以改寫的地方嗎?
一定要用二維的方式去儲存嗎?
謝謝
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