From b9992a63adb71a6f4f60c922f03abdd92708fcc0 Mon Sep 17 00:00:00 2001 From: Shivam Chaudhary Date: Fri, 10 Feb 2023 12:34:04 +0100 Subject: [PATCH] Add feature to check eligibility for loan --- src/checkLoanEligibility.c | 30 ++++++++++++++++++++++++++++++ src/checkLoanEligibility.h | 10 ++++++++++ 2 files changed, 40 insertions(+) create mode 100644 src/checkLoanEligibility.c create mode 100644 src/checkLoanEligibility.h diff --git a/src/checkLoanEligibility.c b/src/checkLoanEligibility.c new file mode 100644 index 0000000..e3ba64c --- /dev/null +++ b/src/checkLoanEligibility.c @@ -0,0 +1,30 @@ +#include "checkLoanEligibility.h" +#include "_file_information.h" + +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"); + + 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); + return eligibility; + +} \ No newline at end of file diff --git a/src/checkLoanEligibility.h b/src/checkLoanEligibility.h new file mode 100644 index 0000000..4415c60 --- /dev/null +++ b/src/checkLoanEligibility.h @@ -0,0 +1,10 @@ +#ifndef CHECKLOANELIGIBILITY_H_ +#define CHECKLOANELIGIBILITY_H_ + +#include +#include +#include + +bool checkLoanEligibility(int user_id); + +#endif \ No newline at end of file