#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);
}
}
写着玩玩的密码验证
最新推荐文章于 2022-03-29 16:28:25 发布