#include <stdio.h> #include <string.h> #include <Windows.h> #include <stdlib.h> int main() { int i; char password[]={0}; //首先定义一个数组,先不在里面放入数据。 for (i=1;i<=3;i++) //也可以使用 { scanf ("%s",password); //通过SCANF函数进行输入值到数组 if(strcmp(password,"123456")==0) //用IF函数进行判断 { printf("登陆成功\n"); break; } else { printf ("密码错误,请重新输入密码\n"); } } if (i==4) { system("cls"); //在下方引用了几个系统函数和休眠函数,让输入界面更加互动。 printf ("------------>"); Sleep(1000); printf ("密码错误三次即将退出程序\n"); Sleep(1000); system("cls"); } return 0; }