與 194741 類似,此處為精簡版本,密碼 "123456",3 次失敗延遲 3 秒退出。
#include <stdio.h>
#include <string.h>
#include <windows.h>
int main() {
const char *pwd = "123456";
char input[10];
for (int i=0; i<3; i++) {
printf("請輸入密碼:");
scanf("%s", input);
if (strcmp(pwd, input)==0) { puts("登錄成功!"); return 0; }
puts("密碼錯誤!");
}
puts("三次錯誤,3秒後關閉");
Sleep(3000);
return 0;
}
請輸入密碼:123456
登錄成功!
請輸入密碼:111
密碼錯誤!
請輸入密碼:222
密碼錯誤!
請輸入密碼:333
密碼錯誤!
三次錯誤,3秒後關閉
bool verify_pwd(int max_try, int lock_ms)。fgets 替代 scanf 避免緩衝區問題。termios/conio.h)。