私はATM用のプログラムを書いています。私の.txt
ファイルは口座残高です (この場合は 1500.00)。.txt
ファイルを読み込んで口座残高を編集し、ファイルに保存するにはどうすればよいですか?
たとえば、ユーザーに 300.00 のデポジットを入力するように依頼した場合、その 300.00 をファイル内の既存の 1500.00 に追加し、1500.00 を合計金額の 1800.00 で上書きできるようにします。
これは私がこれまでに持っているものです。
float deposit;
float var;
printf("Current account balance:");
if ( (file_account = fopen ("account.txt", "r")) == NULL)
{
printf ("Error finding account balance.\n");
return;
}
while ( (fscanf (file_account, "%c", &var)) != EOF)
{
printf ("%c", var);
}
printf ("\n");
fclose (file_account);
for (deposit=0; deposit>0; deposit++)
{
if (deposit > 0)
{
printf ("Enter amount to deposit:");
scanf ("%f", &deposit);
//file_account + deposit;
fprintf (file_account, "Your new account balance is: %f", deposit);
}
else
{
printf ("Amount must be 0 or more.");
}
fclose (file_account);
}