Browse Source

Refactor loanEligibility

remotes/origin/Alpha
fdlt3817 2 years ago
parent
commit
1f6796c3e6
  1. 28
      src/checkLoanEligibility.c

28
src/checkLoanEligibility.c

@ -2,29 +2,19 @@
#include "_file_information.h" #include "_file_information.h"
bool checkLoanEligibility(int user_id) { bool checkLoanEligibility(int user_id) {
// Eligible only when user is present in CustomerDataFile
bool keep_reading = true;
bool eligibility = false;
char buffer[MAX_LENGTH];
FILE *file = fopen(CUSTOMER_DATA_FILE, "r"); FILE *file = fopen(CUSTOMER_DATA_FILE, "r");
if (file == NULL) {
return false;
}
while(keep_reading) { int customer_id;
fgets(buffer, MAX_LENGTH, file); while (fscanf(file, "%d", &customer_id) == 1) {
if (customer_id == user_id) {
if (feof(file)) { fclose(file);
keep_reading = false; return true;
}
if(user_id == atoi(buffer)) {
eligibility = true;
keep_reading = false;
} }
} }
fclose(file); fclose(file);
return eligibility; return false;
} }
|||||||
100:0
Loading…
Cancel
Save