From 87a32f9bf6fb620f2ad8c3595ef63f76bd46a1d5 Mon Sep 17 00:00:00 2001 From: fdlt3817 Date: Thu, 2 Feb 2023 14:30:26 +0100 Subject: [PATCH] Function functionality change updateAvailabeAccountBalance no longer increases or decreases the balance but rather sets the balance to the input value. --- src/updateCustomerAccountBalance.c | 13 ++----------- src/updateCustomerAccountBalance.h | 4 ++-- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/src/updateCustomerAccountBalance.c b/src/updateCustomerAccountBalance.c index 566f2fd..2040a6d 100644 --- a/src/updateCustomerAccountBalance.c +++ b/src/updateCustomerAccountBalance.c @@ -44,10 +44,9 @@ void replaceBalanceInString(float replacementBalance, int currentLine) { replaceLineInFile("CustomerData.txt",currentLine,newBalanceLine); } -bool updateAvailableAccountBalance(int user_id, float changeInBalance, bool positive){ +bool updateAvailableAccountBalance(int user_id, float newBalance){ bool keep_reading = true; - float availableBalance = 0; char buffer[MAX_LENGTH]; char stringID[MAX_LENGTH] = "ID="; @@ -73,18 +72,10 @@ bool updateAvailableAccountBalance(int user_id, float changeInBalance, bool posi fgets(buffer, MAX_LENGTH, file); strcpy(balance_String, buffer); currentLine+=4; - availableBalance = fetchBalanceFromBalanceString(balance_String); keep_reading = false; } } - fclose(file); - float newBalance = (positive) ? availableBalance+changeInBalance : availableBalance-changeInBalance; + fclose(file);; replaceBalanceInString(newBalance,currentLine); } -int main(){ - - updateAvailableAccountBalance(1234,500,true); - - return 0; -} \ No newline at end of file diff --git a/src/updateCustomerAccountBalance.h b/src/updateCustomerAccountBalance.h index 4af3f89..29f5b75 100644 --- a/src/updateCustomerAccountBalance.h +++ b/src/updateCustomerAccountBalance.h @@ -6,6 +6,6 @@ #define MAX_LENGTH 100 -bool updateAvailableAccountBalance(int user_id, float changeInBalance, bool positive); +bool updateAvailableAccountBalance(int user_id, float newBalance); -void replaceBalanceInString(float replacementBalance, int currentLine); \ No newline at end of file +void replaceBalanceInString(float replacementBalance, int currentLine);