|
@ -2,19 +2,29 @@ |
|
|
#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; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int customer_id; |
|
|
|
|
|
while (fscanf(file, "%d", &customer_id) == 1) { |
|
|
|
|
|
if (customer_id == user_id) { |
|
|
|
|
|
fclose(file); |
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
|
while(keep_reading) { |
|
|
|
|
|
fgets(buffer, MAX_LENGTH, file); |
|
|
|
|
|
|
|
|
|
|
|
if (feof(file)) { |
|
|
|
|
|
keep_reading = false; |
|
|
|
|
|
} |
|
|
|
|
|
if(user_id == atoi(buffer)) { |
|
|
|
|
|
eligibility = true; |
|
|
|
|
|
keep_reading = false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
fclose(file); |
|
|
fclose(file); |
|
|
return false; |
|
|
|
|
|
|
|
|
return eligibility; |
|
|
|
|
|
|
|
|
} |
|
|
} |