Presentation is loading. Please wait.

Presentation is loading. Please wait.

Conio.h與time.h簡介 ANT製作 上課日期:2010/05/19.

Similar presentations


Presentation on theme: "Conio.h與time.h簡介 ANT製作 上課日期:2010/05/19."— Presentation transcript:

1 conio.h與time.h簡介 ANT製作 上課日期:2010/05/19

2 conio.h(1/6) getch (void); getche (void); kbhit (void); putch (int);
ungetch (int);

3 conio.h(2/6) int kbhit(void); int putch(int c);
Checks if a keyboard key has been pressed but not yet read. Returns a non-zero value if a key was pressed. Otherwise, returns 0. int putch(int c); The putch function writes character c to the console, without buffering.

4 conio.h(3/6) int getch(void); int getche(void); int ungetch(int c);
Gets a character from the console without echo. int getche(void); Gets a character from the console with echo. int ungetch(int c); Pushes back the last character read from the console.

5 conio.h(4/6) 範例1:等待從鍵盤輸入,並顯示輸入字元後離開while迴圈。
動動腦1:如果getche()替換成getch(),執行結果會有什麼變化? 動動腦2:如果將while迴圈中的敘述句(第8和9行)註解起來,執行結果會有什麼變化?

6 conio.h(5/6) 利用getch()記錄鍵盤輸入字元 動動腦:getch()和scanf(“%c”,input);差異在哪?

7 conio.h(6/6) 將鍵盤輸入的字元顯示到螢幕上。

8 time.h(1/6) time_t time(time_t *timeptr);
time returns the current time in seconds elapsed since 00:00:00 GMT on January 1, 1968 and stores that value in *timeptr if timeptr is not NULL. double difftime (time_t time2, time_t time1);

9 time.h(2/6) Sleep();是定義在windows.h中,單位是ms

10 time.h(3/6) char *asctime(const struct tm *ntime);
struct tm *localtime(time_t *stime);

11 time.h(4/6) char *ctime(const time_t *ntime);
Converts the calendar time (type time_t) pointed to by ntime to local time in the form of an ASCII string. It is equivalent to the function call asctime(localtime(ntime)).

12 time.h(5/6) Returns pointer to a static ASCII string of 26 characters. The string will be overwritten by each call to ctime. The string's form is: DDD MMM dd hh:mm:ss YYYY\n\0

13 time.h(6/6) 顯示目前的時間 asctime()和ctime()差異在於傳入function參數的型態不同

14 參考資料 http://www.digitalmars.com/rtl/conio.html

15 Lab09 加密文練習 說明:將鍵盤輸入的字用*表示,直到使用者按下Enter鍵後,才在畫面顯示剛剛使用者輸入的內容。
注意:使用者按空白鍵畫面會顯示*

16 HW09(1/4) 簡易計時打字練習 說明:畫面會隨機出現a到z的字母。使用者從鍵盤輸入,只要鍵盤有輸入,字母就會消失並出現下一個字母,輸入錯誤會記錄key錯幾次。使用者需達成正確消除20個字母(不須連續)方能過關。 提示:需用到之前conio0.h的function

17 HW09(2/4) 程式需求: 在螢幕框出字母在螢幕出現的範圍
從a~z的字母中隨機挑出一個字母出現在框框中,字母在框框中的位子也是隨機的,字母會漸漸掉落 只要鍵盤有輸入,畫面的字母就會替換(原本的消失,出現新的字母) 畫面需顯示打錯幾次 畫面需顯示使用者達成任務所花耗的時間

18 HW09(3/4) 一開始的畫面 距離任務完成還有幾個字母 (正確輸入字母即遞減,錯誤輸入該數量並不會增加) 錯誤輸入計數器

19 HW09(4/4) 達成任務的畫面 任務達成的提示語! 達成任務所花費的時間


Download ppt "Conio.h與time.h簡介 ANT製作 上課日期:2010/05/19."

Similar presentations


Ads by Google