Hi guys. I'm having trouble with overwriting a specific field in my struct. Anyone can help me? What should I do? Please help.
Code:
void Deposit(FILE *fp, struct information info, char set[]){
int x, flag;
float deposit;
char id[8];
fp=fopen("account.dat","a+b");
system("cls");
printf("=========DEPOSIT=========");
printf("\nEnter Account ID:(XX-XXX)");
gotoxy(18,1);scanf("%6s",id);
flag=0;
if (id[2]!='-' || strspn(id,set)!=6)
{ /*format*/
flag=1;
system("cls");
printf("Invalid Account# format! ");
printf("\nPress any key to continue..");
getch();
} /*format*/
if (flag==0)
{
while(fread(&info, sizeof(struct information), 1, fp) != NULL)
{
if(strcmp(id,info.id)==0)
{
system("cls");
printf("Account# found!");
printf("\nPress any key to continue..");
flag=2;
getch();
}
}
}
if (flag==2)
{
system("cls");
printf("\nEnter deposit amount: ");
scanf("%f", &deposit);
if (deposit <= 0)
{
printf("\nInvalid amount.");
getch();
}
else
{
info.obalance+=deposit;
fwrite(&info,sizeof(struct information),1,fp);
}
getch();
}
fclose(fp);
}