Robofun 機器人論壇

標題: 請問這個split函式該如何使用? [打印本頁]

作者: pizg    時間: 2012-12-18 23:26
標題: 請問這個split函式該如何使用?

  1. int count_delimiters(char str[], const char* delimiters) {
  2.   int i, j, result = 0;
  3.   for (i = 0; i < strlen(str); ++i) {
  4.     for (j = 0; j < strlen(delimiters); ++j) {
  5.       if (str[i] == delimiters[j]) {
  6.         ++result;
  7.       }
  8.     }
  9.   }
  10.   return (result + 1);
  11. }

  12. char** split(char str[], const char* delimiters) {
  13.   int result_size = count_delimiters(str, delimiters);
  14.   int i = 0;
  15.   char* result[result_size];
  16.   char* pch = strtok(str, ",");

  17.   while (pch != NULL) {
  18.     result[i] = pch;
  19.     pch = strtok(NULL, ",");
  20.     ++i;
  21.   }

  22.   return result;
  23. }
複製代碼





歡迎光臨 Robofun 機器人論壇 (https://robofun.net/forum/) Powered by Discuz! X3.2