代码如下:
#include<stdio.h>
#pragma warning(disable:4996)
#include<string.h>
int main()
{
int i = 0
char password[10] = { 0 }
printf("请输入密码:")
while (i <3)
{
scanf("%s", password)
printf("\n")
if (strcmp(password, "972816") == 0)
{
printf("登录成功\n")
break
}
else
{
i++
if (i != 3)
printf("再输入一次")
}
}
if (i == 3)
printf("密码错误三次退出登录界面\n")
system("pause")
return 0
扩展资料:
#include后面有两种方式,<>;和""前者先在标准库中查找,查找不到在path中查找。后者为文件路径,若直接是文件名则在项目根目录下查找。
引用方法:#include <stdio.h>
注意事项:在TC2.0中,允许不引用此头文件而直接调用其中的函数,但这种做法是不标准的。也不建议这样做。以避免出现在其他IDE中无法编译或执行的问题。
参考资料来源:百度百科—stdio.h
#include <stdio.h>#include<string.h>main() { FILE *fpchar pswd[100], enter[100]int iif((fp=fopen("password.txt","r"))==NULL) { puts("password file not exist")return 1} fgets(pswd,100,fp)printf("plz enter pswd:")gets(enter)i=3while(i-->0) if(strcmp(enter,pswd)==0) puts("welcome!")else printf("pswd error,try again:")if(i==-1) puts("login error!")}