Re: [問題] 字串處理問題

看板C_and_CPP作者 (CA)時間15年前 (2009/08/01 11:52), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/4 (看更多)
※ 引述《jeremyhcw ((  ̄ c ̄)y▂ξ)》之銘言: : problem: : 算一算每行有幾個字(word)。 : 範例輸入: : Hello everybody!! : This is school principal speeking. : 範例輸出 : : 2 : 5 : 我的程式 : #include <stdio.h> 醜一點: for(char l[1024];fgets(l,1024,stdin);) { int i=0,n=0; for(char w[1024],*t=l;sscanf(t," %s%n ",w,&n)==1;++i,t+=n); printf("%d\n",i); } C99 限定 ==== 其實你用 getchar 抓字元判斷 alphabet => space 就好 換行就重新計算 -- 自High筆記(半荒廢) http://legnaleurc.blogspot.com/ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.64.167.181
文章代碼(AID): #1ASxlsNI (C_and_CPP)
文章代碼(AID): #1ASxlsNI (C_and_CPP)