写着玩玩的密码验证

来源:互联网 发布:pc录屏软件 编辑:程序博客网 时间:2024/04/28 00:39
#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;elsereturn 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); }}

0 0
原创粉丝点击