在屏幕輸入時(shí)密碼用*號(hào)代替密碼為123時(shí)為高級(jí)玩家321時(shí)為超級(jí)玩家
1 回答

慕萊塢森
TA貢獻(xiàn)1810條經(jīng)驗(yàn) 獲得超4個(gè)贊
#include <conio.h> #include <iostream> using namespace std; int main() { char* password; int length = 3; password = new char[length + 1]; char* p = NULL; int count = 0; cout << "Input password : "; p = password; count = 0; //fflush(stdin); while (((*p = getch()) != 13) && count < length) { // 這里不是'\n'(10), new line // 而是'\r'(13), reback. 即是按下回車鍵,好像這個(gè)東西是linux的. // 主要是與getch這個(gè)函數(shù)有關(guān). putch('*'); fflush(stdin); p++; count++; } password[count] = '\0'; cout << endl; if (strcmp(password, "123") == 0) { cout << "高級(jí)玩家" << endl; } else if (strcmp(password, "321") == 0) { cout << "超級(jí)玩家" << endl; } else { cout << "普通玩家" << endl; } delete []password; password = NULL; system("pause"); return 0; }
- 1 回答
- 0 關(guān)注
- 922 瀏覽
添加回答
舉報(bào)
0/150
提交
取消