//存款函数
void deposit()
{
struct client message;
struct business note;
FILE *fp_1;
FILE *fp_2;
char reply='y';
char found='n';
int size=sizeof(struct client);
fp_1=fopen("message.dat","r+w");
fp_2=fopen("note_message.dat","a");
if (fp_1==NULL)
{
printf("\n文件错误\n");
printf("\n按任意返回主菜单……");
getchar();
return;
}
if (fp_2==NULL)
{
printf("\n文件错误\n");
printf("\n按任意返回主菜单……");
getchar();
return;
}
while (reply=='y')
{
system("cls");
found='n';
printf("\n请输入你的信用卡号:");
scanf("%d",¬e.business_code);
while ((fread(&message,sizeof(struct client),1,fp_1))==1)
{
if (note.business_code==message.client_code)
{
found='y';
note.business_type='D';
break;
}
}
if (found=='y')
{
printf("\n请输入存款金额:");
scanf("%d",¬e.business_money);
message.client_money+=note.business_money;
}
fwrite(¬e,sizeof(struct business),1,fp_2);
fseek(fp_1,-size,1);
fwrite(&message,sizeof(struct client),1,fp_1);
printf("\n==============================\n");
printf("\n信用卡号:%d\n",message.client_code);
printf("\n客户姓名:%s\n",message.client_name);
printf("\n帐户余额:%d\n",message.client_money);
printf("\n==============================\n");
printf("\n是否需要继续?(y/n):");
scanf(" %c",&reply);
}
fclose(fp_1);
fclose(fp_2);
printf("\n按任意返回主菜单……");
getchar();
getchar();
}
void deposit()
{
struct client message;
struct business note;
FILE *fp_1;
FILE *fp_2;
char reply='y';
char found='n';
int size=sizeof(struct client);
fp_1=fopen("message.dat","r+w");
fp_2=fopen("note_message.dat","a");
if (fp_1==NULL)
{
printf("\n文件错误\n");
printf("\n按任意返回主菜单……");
getchar();
return;
}
if (fp_2==NULL)
{
printf("\n文件错误\n");
printf("\n按任意返回主菜单……");
getchar();
return;
}
while (reply=='y')
{
system("cls");
found='n';
printf("\n请输入你的信用卡号:");
scanf("%d",¬e.business_code);
while ((fread(&message,sizeof(struct client),1,fp_1))==1)
{
if (note.business_code==message.client_code)
{
found='y';
note.business_type='D';
break;
}
}
if (found=='y')
{
printf("\n请输入存款金额:");
scanf("%d",¬e.business_money);
message.client_money+=note.business_money;
}
fwrite(¬e,sizeof(struct business),1,fp_2);
fseek(fp_1,-size,1);
fwrite(&message,sizeof(struct client),1,fp_1);
printf("\n==============================\n");
printf("\n信用卡号:%d\n",message.client_code);
printf("\n客户姓名:%s\n",message.client_name);
printf("\n帐户余额:%d\n",message.client_money);
printf("\n==============================\n");
printf("\n是否需要继续?(y/n):");
scanf(" %c",&reply);
}
fclose(fp_1);
fclose(fp_2);
printf("\n按任意返回主菜单……");
getchar();
getchar();
}