Browse Source

Function functionality change

updateAvailabeAccountBalance no longer increases or decreases the balance but rather sets the balance to the input value.
remotes/origin/feature/update-current-customer-account-balance
fdlt3817 2 years ago
parent
commit
87a32f9bf6
  1. 13
      src/updateCustomerAccountBalance.c
  2. 2
      src/updateCustomerAccountBalance.h

13
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;
}

2
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);
Loading…
Cancel
Save