doing this simple program. This is just the firt part of a banking service program. Somehow, I am stuck with this fread()
. I cant compare the input of the user and my database. When my program starts, after I input user and pass it kinda 'hang' or 'freeze' then a popup will appear and says "end program". BTW I am using Dev C++.
#include<stdio.h>
#include<string.h>
struct client
{
char accnum[9];
char accode[5];
char fname[20];
char lname[20];
}s;
main()
{
FILE *fp;
char user[9];
char pass[5];
fp=fopen("account.txt","a");
if(fp!=NULL)
{
/**
strcpy(s.accnum,"abcd1234");
strcpy(s.accode,"1234");
strcpy(s.fname,"john");
strcpy(s.lname,"doe");
fwrite(&s,sizeof(s),1,fp);
**/
printf("BANKING SERVICE");
printf("\nInput User: ");
gets(user);
printf("\nInput Pass: ");
gets(pass);
while(!feof(fp))
{
while(fread(&s,sizeof(s),1,fp)==1);
{
if(ferror(fp))
{
printf("error");
}
if (strcmp(user,s.accnum) == 0 && strcmp(pass,s.accode) == 0)
{
printf("\n\nsuccess!");
}
else
{
printf("\n\nerror!");
}
}
}
fclose(fp);
}
fclose(fp);
getch();
}