|
@ -1,7 +1,8 @@ |
|
|
#include "updateCustomerAccountBalance.h" |
|
|
#include "updateCustomerAccountBalance.h" |
|
|
#include "currentCustomerAccountBalance.c" |
|
|
#include "currentCustomerAccountBalance.c" |
|
|
|
|
|
#include "lineReplacer.h" |
|
|
|
|
|
|
|
|
void deleteLineFromFile(const char* file_name, int line, const char* new_line){ |
|
|
|
|
|
|
|
|
void replaceLineInFile(const char* file_name, int line, const char* new_line){ |
|
|
FILE* file = fopen(file_name, "r"); |
|
|
FILE* file = fopen(file_name, "r"); |
|
|
if (file == NULL) { |
|
|
if (file == NULL) { |
|
|
printf("Error opening file!\n"); |
|
|
printf("Error opening file!\n"); |
|
@ -39,10 +40,10 @@ void replaceBalanceInString(float replacementBalance, int currentLine) { |
|
|
char balance_as_string[MAX_LENGTH]; |
|
|
char balance_as_string[MAX_LENGTH]; |
|
|
sprintf(balance_as_string, "%g", replacementBalance); //converts replacement balance to string |
|
|
sprintf(balance_as_string, "%g", replacementBalance); //converts replacement balance to string |
|
|
strcat(newBalanceLine, balance_as_string); |
|
|
strcat(newBalanceLine, balance_as_string); |
|
|
deleteLineFromFile("CustomerData.txt",currentLine,newBalanceLine); |
|
|
|
|
|
|
|
|
replaceLineInFile("CustomerData.txt",currentLine,newBalanceLine); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
bool updateAvailableAccountBalance(int user_id, float changeInBalance){ |
|
|
|
|
|
|
|
|
bool updateAvailableAccountBalance(int user_id, float changeInBalance, bool positive){ |
|
|
|
|
|
|
|
|
bool keep_reading = true; |
|
|
bool keep_reading = true; |
|
|
float availableBalance = 0; |
|
|
float availableBalance = 0; |
|
@ -72,18 +73,18 @@ bool updateAvailableAccountBalance(int user_id, float changeInBalance){ |
|
|
strcpy(balance_String, buffer); |
|
|
strcpy(balance_String, buffer); |
|
|
currentLine+=4; |
|
|
currentLine+=4; |
|
|
availableBalance = fetchBalanceFromBalanceString(balance_String); |
|
|
availableBalance = fetchBalanceFromBalanceString(balance_String); |
|
|
|
|
|
|
|
|
keep_reading = false; |
|
|
keep_reading = false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
fclose(file); |
|
|
fclose(file); |
|
|
replaceBalanceInString(availableBalance+changeInBalance,currentLine); |
|
|
|
|
|
|
|
|
float newBalance = (positive) ? availableBalance+changeInBalance : availableBalance-changeInBalance; |
|
|
|
|
|
replaceBalanceInString(newBalance,currentLine); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
int main(){ |
|
|
int main(){ |
|
|
|
|
|
|
|
|
updateAvailableAccountBalance(1234,500); |
|
|
|
|
|
|
|
|
updateAvailableAccountBalance(1234,500, true); |
|
|
return 0; |
|
|
return 0; |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|