Browse Source

Bug fix: A line would get removed after the replaced line.

remotes/origin/feature/update-current-customer-account-balance
fdlt3817 2 years ago
parent
commit
a527960e62
  1. 2
      src/CustomerData.txt
  2. BIN
      src/a.exe
  3. 7
      src/updateCustomerAccountBalance.c

2
src/CustomerData.txt

@ -3,7 +3,7 @@ ID=1234
forename=Max forename=Max
Surname=Mustermann Surname=Mustermann
password=example password=example
balance=2000
balance=5000
1327=example 1327=example
ID=1327 ID=1327

BIN
src/a.exe

7
src/updateCustomerAccountBalance.c

@ -20,6 +20,7 @@ void replaceLineInFile(const char* file_name, int line, const char* new_line){
while (fgets(current_string, sizeof(current_string), file) != NULL) { while (fgets(current_string, sizeof(current_string), file) != NULL) {
if (current_line == line) { if (current_line == line) {
fprintf(temp_file, "%s", new_line); fprintf(temp_file, "%s", new_line);
fputs("\n", temp_file);
} else { } else {
fprintf(temp_file, "%s", current_string); fprintf(temp_file, "%s", current_string);
} }
@ -81,3 +82,9 @@ bool updateAvailableAccountBalance(int user_id, float changeInBalance, bool posi
float newBalance = (positive) ? availableBalance+changeInBalance : availableBalance-changeInBalance; float newBalance = (positive) ? availableBalance+changeInBalance : availableBalance-changeInBalance;
replaceBalanceInString(newBalance,currentLine); replaceBalanceInString(newBalance,currentLine);
} }
int main(){
updateAvailableAccountBalance(1234,500,true);
return 0;
}
Loading…
Cancel
Save