第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

什么是Linux中的Getch()&getche()?

什么是Linux中的Getch()&getche()?

狐的傳說 2019-07-01 09:58:19
什么是Linux中的Getch()&getche()?我無法在Linux中找到conio.h的等效頭文件。有什么可供選擇的嗎?getch() & getche()Linux中的函數(shù)?我想做一個開關案例基礎菜單,用戶將提供他的選擇,只要按一個鍵&進程應該向前移動。我不想讓用戶按回車后,按下他的選擇。
查看完整描述

3 回答

?
qq_遁去的一_1

TA貢獻1725條經(jīng)驗 獲得超8個贊

#include <termios.h>#include <stdio.h>static struct termios old, new;/* Initialize new terminal i/o settings */void initTermios(int echo) {
  tcgetattr(0, &old); /* grab old terminal i/o settings */
  new = old; /* make new settings same as old settings */
  new.c_lflag &= ~ICANON; /* disable buffered i/o */
  if (echo) {
      new.c_lflag |= ECHO; /* set echo mode */
  } else {
      new.c_lflag &= ~ECHO; /* set no echo mode */
  }
  tcsetattr(0, TCSANOW, &new); /* use these new terminal i/o settings now */}/* Restore old terminal i/o settings */void resetTermios(void) {
  tcsetattr(0, TCSANOW, &old);}/* Read 1 character - echo defines echo mode */char getch_(int echo) {
  char ch;
  initTermios(echo);
  ch = getchar();
  resetTermios();
  return ch;}/* Read 1 character without echo */char getch(void) {
  return getch_(0);}/* Read 1 character with echo */char getche(void) {
  return getch_(1);}/* Let's test it out */int main(void) {
  char c;
  printf("(getche example) please type a letter: ");
  c = getche();
  printf("\nYou typed: %c\n", c);
  printf("(getch example) please type a letter...");
  c = getch();
  printf("\nYou typed: %c\n", c);
  return 0;}

只需復制這些函數(shù)并使用它。我很久以前就在谷歌上找到了這個片段,我保存了它,最后我為你打開了很長一段時間,希望它能幫助你!謝謝


查看完整回答
反對 回復 2019-07-01
?
POPMUISE

TA貢獻1765條經(jīng)驗 獲得超5個贊

char getch(){
    /*#include <unistd.h>   //_getch*/
    /*#include <termios.h>  //_getch*/
    char buf=0;
    struct termios old={0};
    fflush(stdout);
    if(tcgetattr(0, &old)<0)
        perror("tcsetattr()");
    old.c_lflag&=~ICANON;
    old.c_lflag&=~ECHO;
    old.c_cc[VMIN]=1;
    old.c_cc[VTIME]=0;
    if(tcsetattr(0, TCSANOW, &old)<0)
        perror("tcsetattr ICANON");
    if(read(0,&buf,1)<0)
        perror("read()");
    old.c_lflag|=ICANON;
    old.c_lflag|=ECHO;
    if(tcsetattr(0, TCSADRAIN, &old)<0)
        perror ("tcsetattr ~ICANON");
    printf("%c\n",buf);
    return buf;
 }

復制這個函數(shù)并使用它,別忘了包括

remove the last printf if you dont want the char to be displayed


查看完整回答
反對 回復 2019-07-01
  • 3 回答
  • 0 關注
  • 837 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號