#include #include /* copy input to output; 1st version */
//getchar()是stdio.h中的庫函式,它的作用是從stdin流中讀入乙個字元,也就是說,如果stdin有資料的話不用輸入它就可以直接讀取了,
//第一次呼叫getchar()時,確實需要人工的輸入,但是如果你輸了多個字元,以後的getchar()再執行時就會直接從緩衝區中讀取了
//getchar
//getchar可用巨集實現:#define getchar() getc(stdin)。getchar有乙個int型的返回值。
//當程式呼叫getchar時.程式就等著使用者按鍵。使用者輸入的字元被存放在鍵盤緩衝區中。
//直到使用者按回車為止(回車字元也放在緩衝區中)。
//當使用者鍵入回車之後,getchar才開始從stdin流中每次讀入乙個字元。
//getchar函式的返回值是使用者輸入的字元的ascii碼,若檔案結尾(end - of - file)則返回 - 1(eof),且將使用者輸入的字元回顯到螢幕。
//如使用者在按回車之前輸入了不止乙個字元,其他字元會保留在鍵盤快取區中,等待後續getchar呼叫讀取。
//也就是說,後續的getchar呼叫不會等待使用者按鍵,而直接讀取緩衝區中的字元,直到緩衝區中的字元讀完後,才等待使用者按鍵。
void main()
int c;
while ((c = getchar()) != eof)
putchar(c);
}
// 統計輸入的行數,單詞數,字元數
void main()
} printf("%d %d %d\n", nl, nw, nc);
}
#include #define maxline 1000 // maximum input line length
// 程式讀入一組文字行,並把最長的文字行列印出來
//演算法的基本框架:
//while(還有未處理的行)
//if(該行比已處理的最長行還長)
//儲存改行為最長行
//儲存改行的長度
//列印最長行
int getline(char line, int maxline);
void copy(char to,char from);
/* print the longest input line */
void main()
} if (max > 0) }
/* read a line into s,return length */
int getline(char s, int lim)
} s[i] = '\0';
return i;
}/* copy: copy 'from' into 'to'; assume to is big enough */
void copy(char to, char from)
統計輸入中的行數,單詞數,字元數
源於 the c programming language p14的一道例題 統計輸入中的行數,單詞數,字元數 單詞的定義 其中不包括空格,製表符,換行符的字串行 include define in 1 define out 0 int main int c,nl,nw,nc,state state...
關於Mysql的統計行數與影響行數
在使用mysql中,我們進行更新操作,經常獲取行數,不論是更新操作影響的行數還是查詢統計的行數 一 影響行數 通常在進行更新操作,insert delete update時,我們對executeupdate 方法的返回值進行記錄,該值為integer型 二 統計行數 在進行查詢操作時,我們經常用到s...
統計程式的行數
public class linecounter string path args 0 string exts args 1 if args.length 2 stringtokenizer stok new stringtokenizer exts,while stok.ha oretokens ...