1. 程式人生 > 實用技巧 >資料檔案——將從鍵盤裝置檔案讀取文字將其寫入顯示器裝置檔案

資料檔案——將從鍵盤裝置檔案讀取文字將其寫入顯示器裝置檔案

程式碼:

 1 //This is c program code!
 2 /* *=+=+=+=+* *** *=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
 3   * 文件資訊: *** :~/WORKM/stutyCode/cCode/recipesProblemSolution/chapter06/test6_23.c
 4   * 版權宣告: *** :(魎魍魅魑)MIT
 5   * 聯絡信箱: *** :[email protected]
 6   * 建立時間: *** :2020年11月22日的下午02:48
 7   * 文件用途: *** :資料結構與演算法分析-c語言描述
 8   * 作者資訊: *** :guochaoxxl(
http://cnblogs.com/guochaoxxl) 9 * 修訂時間: *** :2020年第46周 11月22日 星期日 下午02:48 (第327天) 10 * 檔案描述: *** :自行新增 11 * *+=+=+=+=* *** *+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+*/ 12 #include <stdio.h> 13 14 #define SIZE 500 15 16 int main(int argc, char **argv) 17 { 18 char
text[SIZE]; 19 puts("Type the text. The text you type form the contents: "); 20 puts("of the device-file keyboard. Strike the function"); 21 puts("ke F6 to signify the end of this file."); 22 23 int size = 0; 24 int ch = fgetc(stdin); 25 while(ch != EOF){ 26 text[size] = ch;
27 size = size + 1; 28 ch = fgetc(stdin); 29 } 30 31 puts("Contents of device-file keyboard are now:"); 32 puts("writtent to the device-file monitor:"); 33 for(int i = 0; i < size; i++){ 34 fputc(text[i], stdout); 35 } 36 37 return 0; 38 }