linux控制台下密碼輸入解決方案

來源:互聯網
上載者:User

標籤:linux   c   linux shell   

    在linux系統編過C語言程式的碼農應該都知道,其和在windows編程是有很大的區別的,linux下沒有許多在windows下常用的標頭檔,但也有許多windows下沒有的標頭檔,對於初學者來說,是有一定的限制性的,就比如conio.h標頭檔,裡面有許多的函數我們經常使用,因此,我們在windows下一個小系統時,常用的登入環節無法在linux下使用,今天,我就來幫大家解決這一問題。

    1 #include<stdio.h>

    2 char getch()
    3 {    
    4     char c;
    5     system("stty -echo");
    6     system("stty -icanon");
    7     c=getchar();
    8     system("stty icanon");
    9     system("stty echo");
   10     return c;
   11 }    
   12 void main()
   13 {    
   14     int i;
   15     char a[21];
   16     char ch;
   17     printf("請輸入密碼:");
   18     for(i=0;i<20;i++)
   19     {
   20         ch=getch();
   21         if(ch==‘\n‘)
   22         {
   23             a[i]=‘\0‘;
   24             break;
   25         }
   26         putchar(‘*‘);
   27         a[i]=ch;
   28     }
   29     if(i==20)
   30         a[20]=‘\0‘;
   31     printf("%s\n",a);
   32 }          

linux控制台下密碼輸入解決方案

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.