單詞的個數

2022-02-08 12:56:46 字數 675 閱讀 1067

從大神處學習的,主要關鍵是sscanf函式的乙個用法,就是遇到空格時,讀入結束。還有gets函式的乙個點,與scanf不同的是輸入字串是直到換行符時才結束,而scanf函式遇到空格時讀入就結束了。@:

其中乙個思想是用二維陣列記錄一行字串,我覺得這個思想很好。

#include

#include

using namespace std;

char word[100];

char arr[100][100];

int main()

int len,pos;

int k;  

while(gets(word)&&strcmp(word,"#")!=0)  

len=strlen(word);  

char temp[100];   

int cnt=0;  

pos=0;  

while(possscanf(word+pos,"%s",temp);   

for(k=0;kif(strcmp(temp,arr[k])==0)      

break;    

if(k==cnt)      

strcpy(arr[cnt++],temp);    

pos+=strlen(temp)+1;  

cout

單詞的個數

從大神處學習的,主要關鍵是sscanf函式的乙個用法,就是遇到空格時,讀入結束。還有gets函式的乙個點,與scanf不同的是輸入字串是直到換行符時才結束,而scanf函式遇到空格時讀入就結束了。其中乙個思想是用二維陣列記錄一行字串,我覺得這個思想很好。include include using n...

檢索單詞的個數

文字檢索是軟體最常用的乙個功能,用c語言寫一段程式,統計某個檔案中單詞的個數。文字檢索是軟體最常用的乙個功能,下面的 將教你如果使用c語言統計單詞的個數。實現 include include include include argc 統計執行程式時命令列引數的個數 argv 儲存每個引數的字串指標,...

統計單詞個數

輸入 檔名稱 sum123.cpp 作 者 林海雲 完成日期 2014年12月16日 版 本 號 v2.0 問題描述 統計各陣列中單詞的個數 程式輸入 程式輸出 統計結果 include includeusing namespace std int pwordnum char str int mai...