int main()
{
FILE *fp;
char username0[20]={""};
char passwd0[20]={""};
int s=0;
typedef struct users Users;
Users next={"","","",};
fp=fopen("data.txt","r+");
printf("请输入用户名");
scanf("%s",username0);
printf("请输入密码");
scanf("%s",passwd0);
while(s!=EOF)
{
s=fscanf(fp,"%s\t%s\t%s\t%d\n",next.username,next.passwd,next.name,&next.uid);
if((strcmp(next.username,username0)==0)&&(strcmp(next.passwd,passwd0)==0))
{
printf("%s\t",next.name);
printf("%d\n",next.uid);
/*此处增加函数*/
}
}//while(s!=EOF);//猜测原因:读到EOF时,程序继续执行一次,此时,值仍然是前一次读到的值,所以此处改用while替代do-while
fclose(fp);
return 0;
}
转载于:https://www.cnblogs.com/langdexuming/p/4134096.html