#include <stdio.h>
#include <string.h>
int main(int argc, const char *argv[])
{
//输入账号密码,需要东西存储定义两个数组
char account[30]="";char password[30]="";
printf("请输入账号");
scanf("%s",account);
printf("请输入密码");
scanf("%s",password);
//打开文件
FILE*fp=fopen("zhanghaomima","r");
if(NULL==fp)
{
perror("fopen");
return -1;
}
//读取内容,但要定义两个数组来存
char a[30]="";char b[30]="";
int res=0;int flag=0;
//注意因为会中断,所以要循环获取
while(res!=EOF)
{
res=fscanf(fp,"%s",a);
fscanf(fp,"%s",b);
if(strcmp(a,account)==0)
{
flag=1;
if(strcmp(b,password)==0)
{
printf("登陆成功");
break;
}
else
{
printf("密码错误");
break;
}
}
}
if(flag==0)
printf("账户不存在");
return 0;
}
10.9作业
最新推荐文章于 2024-10-15 10:20:47 发布