pizg 发表于 2012-12-18 23:30:32

請問這個 split 函式在 Arduino 裏如何使用?



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 == delimiters) {
                ++result;
            }
      }
    }
    return (result + 1);
}

char** split(char str[], const char* delimiters) {
    int result_size = count_delimiters(str, delimiters);
    int i = 0;
    char* result;
    char* pch = strtok(str, ",");

    while (pch != NULL)
    {
      result = pch;
      pch = strtok(NULL, ",");
      ++i;
    }

    return result;
}
页: [1]
查看完整版本: 請問這個 split 函式在 Arduino 裏如何使用?