getch()、getche()和getchar()函式
(1) getch()和getche()函式
這兩個函式都是從鍵盤上讀入乙個字元。其呼叫格式為:
getch();
getche();
兩者的區別是: getch()函式不將讀入的字元回顯在顯示螢幕上, 而getche()
函式卻將讀入的字元回顯到顯示螢幕上。
例1:
#include
#include
main()
利用回顯和不回顯的特點, 這兩個函式經常用於互動輸入的過程中完成暫停
等功能。
例2:
#include
#include
main()
(2) getchar()函式
getchar()函式也是從鍵盤上讀入乙個字元, 並帶回顯。它與前面兩個函式
的區別在於: getchar()函式等待輸入直到按回車才結束, 回車前的所有輸入字
符都會逐個顯示在螢幕上。但只有第乙個字元作為函式的返回值。
getchar()函式的呼叫格式為:
getchar();
例3:
#include
#include
main()
例4#include
#include
main()
**:getch()等應有標頭檔案#include,下面是解釋:
第一點:
你既然用了getch()函式,在前面就應有標頭檔案#include。因為:
conio是console input/output(控制台輸入輸出)的簡寫,其中定義了通過控制台進行資料輸入和資料輸出的函式,主要是一些使用者通過按鍵盤產生的對應操作,比如getch()函式等等。
包含的函式
cgets(char *);
cprintf(const char *, ...);
cputs(const char *);
cscanf(const char *, ...);
inp(unsigned short);
inpw(unsigned short);
getch(void);
getche(void);
kbhit(void);
outp(unsigned short, int);
outpw(unsigned short, unsigned short);
putch(int);
ungetch(int);
void _cdecl clreol (void);
void _cdecl clrscr (void);
void _cdecl delline (void);
int _cdecl gettext (int left, int top, int right, int bottom,
void *destin);
void _cdecl gettextinfo (struct text_info *r);
void _cdecl gotoxy (int x, int y);
void _cdecl highvideo (void);
void _cdecl insline (void);
void _cdecl lowvideo (void);
int _cdecl movetext (int left, int top, int right, int bottom,
int destleft, int desttop);
void _cdecl normvideo (void);
int _cdecl puttext (int left, int top, int right, int bottom,
void *source);
void _cdecl textattr (int newattr);
void _cdecl textbackground (int newcolor);
void _cdecl textcolor (int newcolor);
void _cdecl textmode (int newmode);
int _cdecl wherex (void);
int _cdecl wherey (void);
void _cdecl window (int left, int top, int right, int bottom);
har *_cdecl cgets (char *str);
int _cdecl cprintf (const char *format, ...);
int _cdecl cputs (const char *str);
int _cdecl cscanf (const char *format, ...);
int _cdecl getch (void);
int _cdecl getche (void);
char *_cdecl getpass (const char *prompt);
int _cdecl kbhit (void);
int _cdecl putch (int c);
int _cdecl ungetch (int ch);
第二點:
你沒弄清getch()的用法。謹記如下:
getch直接從鍵盤獲取鍵值,不等待使用者按回車,只要使用者按乙個鍵,getch就立刻返回,getch返回值是使用者輸入的ascii碼,出錯返回-1.輸入的字元不會回顯在螢幕上.getch函式常用於程式除錯中,在除錯時,在關鍵位置顯示有關的結果以待檢視,然後用getch函式暫停程式執行,當按任意鍵後程式繼續執行.
摘自:
C C 的乙個字元陷阱
事故現場 於乙個鍊錶的刪除功能,先看 移除節點 stgoodsinfo singlelink remove stgoodsinfo phead,int ipos if ipos 0 stgoodsinfo ptemp phead pnext 遍歷到待刪除節點的前乙個節點 for int i 1 ip...
乙個字元驅動
實現乙個基本框架 define notice fmt,args.printk kern notice scull fmt,args define error fmt,args.printk kern err scull fmt,args static init int scull init void...
等等是乙個字元
在使用字串的過程中,我們經常會用到轉義字元,如 等等。對字串中的轉義字元進行操作時,有可能會誤認為這是兩個字元,需要我們根據轉義的定義,將這兩個字元轉換為乙個字元。其實完全不需要,因為對字串進行操作時,計算機自動地將它們識別為乙個字元。include stdio.h int my print str...