From 8e0854cfc08a5e223bf8f081fb2718a52aee504a Mon Sep 17 00:00:00 2001 From: Shivam Chaudhary Date: Sat, 28 Jan 2023 12:15:17 +0100 Subject: [PATCH] Refactoring: minimize code lines for easy understanding --- src/currentCustomerAccountBalance.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/currentCustomerAccountBalance.c b/src/currentCustomerAccountBalance.c index 9d2e365..9f415f9 100644 --- a/src/currentCustomerAccountBalance.c +++ b/src/currentCustomerAccountBalance.c @@ -25,10 +25,9 @@ float readFileAndGetAvailableBalance(FILE *file, char stringID[MAX_LENGTH]) { keep_reading = false; } else if(strstr(buffer, stringID)) { - fgets(buffer, MAX_LENGTH, file); - fgets(buffer, MAX_LENGTH, file); - fgets(buffer, MAX_LENGTH, file); - fgets(buffer, MAX_LENGTH, file); + for (int i = 0; i < 4; i++) { + fgets(buffer, MAX_LENGTH, file); + } strcpy(balance_String, buffer); balance = fetchBalanceFromBalanceString(balance_String); keep_reading = false; @@ -49,7 +48,7 @@ float getAvailableAccountBalance(int user_id) { FILE *file = fopen("CustomerData.txt", "r"); if(file == 0) { - printf("Erro: file cannot be opened!"); + printf("Error: customer data file cannot be opened!"); return 0; } else {