写着玩玩的密码验证

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct student
{
	char name[20];
	char password[20];
	char ID[20];
};

bool operator ==(student& s1,student &s2)
{
	if((strcmp(s1.name,s2.name))==0&&(strcmp(s1.password,s2.password)==0)&&(strcmp(s1.ID,s2.ID)==0))
	    return true;
	else
		return false;
}
int main()
{
	FILE *fp;
	if((fp=fopen("send.txt","w"))==NULL)
	{
		puts("Could not open the file.");
		exit(1);
	}
	student s1={"Taylor", "abc654", "451934578"};
	fprintf(fp,"%s %s %s",s1.name,s1.password,s1.ID);
	fclose(fp);

	FILE *fp1;
		if((fp1=fopen("receice.txt","w"))==NULL)
		{
			puts("Could not open the file.");
			exit(1);
		}
		student s2[5]={{"James", "pass123","451965432"},
				{"John","pwd789","451934567"},
				{"Matt", "345345" ,"451999999"},
				{"Taylor", "abc654" ,"451934578"},
				{"Julia", "654321", "451900001"}};
		fwrite(s2,sizeof(student),5,fp1);
		fclose(fp1);

	FILE *fp3,*fp4;
	if((fp3=fopen("send.txt","r"))==NULL)
		{
		puts("Could not open the file.");
			exit(1);
		}
	if((fp4=fopen("receice.txt","r"))==NULL)
			{
		puts("Could not open the file.");
				exit(1);
			}
	 student temp;
	 fscanf(fp3,"%s %s %s",temp.name,temp.password,temp.ID);
	 student temp_array[5];
	 if(!feof(fp4))
		 fread(temp_array,sizeof(student),5,fp4);
	 for(int i=0;i<5;i++)
	 {
		 if(temp_array[i]==temp)
	       printf("第%d是一样的",i+1);
	 }



}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值