#include <stdio.h>
#include <string.h>
#include <conio.h>

#define MAX_PW_LENGTH 20
#define MAX_TRIES 3

int main() {
    char password[MAX_PW_LENGTH];
    char correct_pw[] = "password";
    int tries = 0;

    while (tries < MAX_TRIES) {
        printf("Please enter the password: ");
        int i = 0;
        char c;
        while ((c = getch()) != '\r') {
            if (c == '\b') { // backspace
                if (i > 0) {
                    i--;
                    printf("\b \b");
                }
            } else if (i < MAX_PW_LENGTH - 1) {
                password[i] = c;
                printf("*");
                i++;
            }
        }
        password[i] = '\0';
        printf("\n");

        if (strcmp(password, correct_pw) == 0) {
            printf("您好,我的主人!\n");
            return 0;
        } else {
            printf("离我远点!\n");
            tries++;
        }
    }

    printf("您已输错三次,程序结束。\n");

    return 0;
}
``
用C语言编写一个程序实现口令检查功能。从键盘输入一个口令与已经存入数组中的口令进行比较;如果口令输人正确屏幕输出 您好我的主人!如果口令输人不正确屏幕显示 离我远点!;可以有三次输入口令的机会。要求输入的口令以显示如输入123屏幕不能显示123以显示。用#includeconioh头文件

原文地址: https://www.cveoy.top/t/topic/ffNO 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录