Robofun 機器人論壇
標題:
請問這個split函式該如何使用?
[打印本頁]
作者:
pizg
時間:
2012-12-18 23:26
標題:
請問這個split函式該如何使用?
int count_delimiters(char str[], const char* delimiters) {
int i, j, result = 0;
for (i = 0; i < strlen(str); ++i) {
for (j = 0; j < strlen(delimiters); ++j) {
if (str[i] == delimiters[j]) {
++result;
}
}
}
return (result + 1);
}
char** split(char str[], const char* delimiters) {
int result_size = count_delimiters(str, delimiters);
int i = 0;
char* result[result_size];
char* pch = strtok(str, ",");
while (pch != NULL) {
result[i] = pch;
pch = strtok(NULL, ",");
++i;
}
return result;
}
複製代碼
歡迎光臨 Robofun 機器人論壇 (https://robofun.net/forum/)
Powered by Discuz! X3.2