Robofun 機器人論壇

用戶名  找回密碼
 申請會員
搜索
熱搜: 活動 交友 discuz
查看: 3142|回復: 0
打印 上一主題 下一主題

請問這個split函式該如何使用?

[複製鏈接]
跳轉到指定樓層
1#
發表於 2012-12-18 23:26:09 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式

  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. }
複製代碼
您需要登錄後才可以回帖 登錄 | 申請會員

本版積分規則

小黑屋|手機版|Archiver|機器人論壇 from 2005.07

GMT+8, 2025-2-26 21:28 , Processed in 0.113043 second(s), 7 queries , Apc On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表