<delect id="sj01t"></delect>
  1. <em id="sj01t"><label id="sj01t"></label></em>
  2. <div id="sj01t"></div>
    1. <em id="sj01t"></em>

            <div id="sj01t"></div>
            C語言

            c語言中getch的用法

            時間:2025-06-02 07:25:36 C語言 我要投稿
            • 相關推薦

            c語言中getch的用法

              getch()函數是無回顯的從控制臺取得一個字符。以利用getch()函數讓程序調試運行結束后等待編程者按下鍵盤才返回編輯界面,即任意鍵繼續效果。下面小編就跟你們詳細介紹下c語言中getch的用法,希望對你們有用。

              c語言中getch的用法如下:

              [cpp] view plain copy

              #include

              #include

              int main()

              {

              int i ;

              i = getch();

              printf("press any key to continue ");

              printf("%d ", i);

              return 0;

              }

              Windows下getch()在conio.h的頭文件中,但conio.h不是標準庫文件,C standard library,ISO C 和POSIX標準中均沒有定義。固然Linux系統中會沒有這個頭文件,網上說在curses.h,然后下載一個庫,但弄了半天也沒成功取得,從網上找到了一個方法實現getch()的功能。

              [cpp] view plain copy

              int getch()

              {

              struct termios tm, tm_old;

              int fd = STDIN_FILENO,c;

              if (tcgetattr(fd, &tm) < 0)

              {

              return -1;

              }

              tm_old = tm;

              cfmakeraw(&tm);

              if (tcsetattr(fd, TCSANOW, &tm) < 0)

              {

              return -1;

              }

              c = fgetc(stdin);

              if (tcsetattr(fd,TCSANOW,&tm_old) < 0)

              {

              return -1;

              }

              return c;

              }

              直接可以這樣用:

              [cpp] view plain copy

              /******************************************************************

              *描述: 實現任意鍵繼續

              *參數: void

              *返回值: void

              *******************************************************************/

              void press_key()

              {

              printf("任意鍵繼續... ");

              getch();

              }

              頭文件

              [cpp] view plain copy

              #include

              #include

              #include

              #include

            【c語言中getch的用法】相關文章:

            C語言中getch()函數詳解(附實例)04-27

            C語言中assert用法02-26

            C語言中sscanf的用法05-09

            c語言中%s的用法07-01

            c語言中邏輯或的用法05-23

            c語言中default的用法05-26

            C語言中assert的用法06-02

            C語言中sizeof的用法04-15

            c語言中多個if的用法02-16

            <delect id="sj01t"></delect>
            1. <em id="sj01t"><label id="sj01t"></label></em>
            2. <div id="sj01t"></div>
              1. <em id="sj01t"></em>

                      <div id="sj01t"></div>
                      黄色视频在线观看