亚洲国产日韩欧美在线a乱码,国产精品路线1路线2路线,亚洲视频一区,精品国产自,www狠狠,国产情侣激情在线视频免费看,亚洲成年网站在线观看

c語言中g(shù)etch的用法

時(shí)間:2025-11-08 19:51:16 C語言 我要投稿

c語言中g(shù)etch的用法

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

  c語言中g(shù)etch的用法如下:

  [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不是標(biāo)準(zhǔn)庫文件,C standard library,ISO C 和POSIX標(biāo)準(zhǔn)中均沒有定義。固然Linux系統(tǒng)中會沒有這個(gè)頭文件,網(wǎng)上說在curses.h,然后下載一個(gè)庫,但弄了半天也沒成功取得,從網(wǎng)上找到了一個(gè)方法實(shí)現(xiàn)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

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

  *描述: 實(shí)現(xiàn)任意鍵繼續(xù)

  *參數(shù): void

  *返回值: void

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

  void press_key()

  {

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

  getch();

  }

  頭文件

  [cpp] view plain copy

  #include

  #include

  #include

  #include

【c語言中g(shù)etch的用法】相關(guān)文章:

C語言中g(shù)etch()函數(shù)詳解(附實(shí)例)08-15

C語言中sizeof的用法12-15

C語言中sscanf的用法11-05

c語言中邏輯或的用法12-15

c語言中free的用法12-11

c語言中bit的用法09-06

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

c語言中多個(gè)if的用法02-16

c語言中fprintf的用法02-02

  • 相關(guān)推薦