close


#include <stdio.h>
#include <stdlib.h>
#include <string.h>


int main() {
   char str[] = "This is a good example"; //要被分割的
   char *s = strtok(str, " "); //分割的判斷字元
   char *put[100]; //分割後放入新的字串陣列
   int s_count=0; //分幾個了


   while(s != NULL) {
     put[s_count++]=s;  //把分出來的丟進去 結果陣列
     s = strtok(NULL, " "); //我不知道 這行幹嘛
   }


   for(int x=0;x<s_count;x++) //驗收成果
      printf("%d %s\n",x,put[x]);


   system("pause");
   return 0;
 }


/*補充 其實改成 strtok(str," @"); 這樣的話
 即使是 This@is a good@example
  也會分成 "This" "is" "a" "good" "example" 了*/


arrow
arrow
    全站熱搜

    finalfrank 發表在 痞客邦 留言(1) 人氣()