引用 | 編輯
zse5500
2009-11-27 01:10 |
樓主
▼ |
||
x0
這張是完成圖=========================== 下面的程式碼是我打的...(不是上面完成圖的程式碼) #include <stdio.h> #include <stdlib.h> #include <conio.h> main() { char pass="OPEN THE DOOR !",g; start: printf("輸入密碼 :"); fflush(stdin); g=getch();g=getch();g=getch();g=getch(); g=getch();g=getch( .. 訪客只能看到部份內容,免費 加入會員 x0
|
引用 | 編輯
totsi
2009-11-27 09:48 |
1樓
▲ ▼ |
pass[]在程式碼裡面沒用到
100代表開一個大小為100的字元陣列 所以那個值依照你的需求改就好了,不過要注意是[0]開始以及有'\0'結尾,所以長度計算時要注意。 Q:g[]=getch(); 怎麼用迴圈化簡? 複製程式 for ( int i = 0 ; i < sizeof(g) ; i++ ) { g[i] = getch(); } x2 |
引用 | 編輯
rchockxm
2009-11-30 20:27 |
2樓
▲ ▼ |
||||||||||
圖 1. 稍微試一下 像這樣嗎? 我只有用最簡單的方法... 重複呼叫自己修改一下就行了 複製程式 #include <stdio.h> #include <stdlib.h> #include <conio.h> #include <string.h> int main() { char input[100], password[]="happy new year !"; printf(" 請輸入密碼:"); int i=0; while((input[i]=getch())!=13&&i<sizeof(input)) { putch('*'); i++; } input[i] = '\0'; i=0; printf("\n\n 您輸入的字串是:%s \n\n", input); if (!strcmp(input,password)) printf(" 恭喜過關 !"); else printf(" 密碼錯誤 !"); printf("\n\n 請按任意鍵繼續..."); getch(); }
x3 |
引用 | 編輯
rchockxm
2009-12-01 21:37 |
4樓
▲ ▼ |
連續取得輸入的字元,直到按下 "Enter" 鍵為止。
後面的 i<sizeof(input) 只是判斷輸入不超過陣列長度。 x1 |
引用 | 編輯
totsi
2009-12-03 09:14 |
6樓
▲ ▼ |
參考來源:http://www.experts-exchange.com/Programming/Languages/C/Q_21263658.html
ASCII Value of Enter Key is a Carriage Return, typically. That is value 13 (Decimal). Windows often uses Carriage Return - Line Feed, which is ASCII 13 decimal, ASCII 10 Decimal. x0 |