希望一个C的高手帮看下错哪里了

来源:百度知道 编辑:UC知道 时间:2024/08/21 03:18:59
这个程序的主要用途是进行登陆验证
密码的源文件在"in.dat"里
格式是123456 123456
654321 654321
相当于是两个帐户,前六位是帐户,后六位是密码
但是我这个程序运行了只能读取第一行的数据
验证第二行就没办法了,有没有高手帮忙看下我程序哪里出问题了
急急急急啊!!!!!!!!!
#include "stdio.h"
#include "bios.h"
#include "dos.h"
#include "conio.h"
#include "stdlib.h"
#include "string.h"
#include "mem.h"
#include "ctype.h"
#include "alloc.h"
#define MAX 4
typedef struct{
char id[8];
char pw[6];
}PRO;
main()
{PRO im[MAX];
char b[6];
char a[6];
int i,j;
FILE *fp;
printf("please feed in your ID:\n");
scanf("%s",a);
fp=fopen("c:\\turboc2\\in.dat","r");
for(i=0;i<MAX;i++)
{fscanf(fp,"%s %s",&im[i].id,&im[i].pw);
if(strcmp(a,im[i].id)==0)
{printf("please feed

原因这样的:
输入的ID首先与第一行ID比较,
如果正确就去检证密码,
如果不正确就说“不是管理员”就退出了。根本没给比较第二行的机会。
正确的思路是这样的。
如果ID正确,当然就去验证密码,
如果错误应该去和下一行的ID作比较,而不是退出程序啊!
只要把以下几行删去就行了。
else
{printf("you are not the administrator\n");
printf("please press any key return\n");
getch();
exit(0);
}