From 1450f6611762aeeccbf654d7eee61cff17671e92 Mon Sep 17 00:00:00 2001 From: fdai7057 Date: Fri, 20 Jan 2023 11:54:11 +0100 Subject: [PATCH] Implementation of writeCustomerPropertiesToFile() --- src/CreateCustomer.c | 20 +++++++++++++++++++- src/CreateCustomer.h | 2 ++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/CreateCustomer.c b/src/CreateCustomer.c index 4d25a1e..4a6c7fd 100644 --- a/src/CreateCustomer.c +++ b/src/CreateCustomer.c @@ -1,5 +1,4 @@ #include "CreateCustomer.h" -#include "CustomerProperties.h" int main() { @@ -81,4 +80,23 @@ void collectCustomerProperties() scanf("%f",&instance.balance); printf("Account successfully created. Your ID is: %d. Note it somewhere!\n",instance.ID); + customer_t *referenceToCustomerInstance = &instance; + writeCustomerPropertiesToFile(referenceToCustomerInstance); +} + +void writeCustomerPropertiesToFile(customer_t *referenceToCustomerInstance) +{ + FILE *customerData = fopen("CustomerData.txt","a"); + if(customerData!=NULL){ + /*calling generateCheckString() at this place in future*/ + fprintf(customerData,"ID=%d\nForename=%s\nSurname=%s\nPassword=%s\nBalance=%.4f€\n\n", + referenceToCustomerInstance->ID,referenceToCustomerInstance->forename, + referenceToCustomerInstance->surname,referenceToCustomerInstance->password, + referenceToCustomerInstance->balance); + fclose(customerData); + } + else{ + printf("Error when accessing the file.\n"); + exit(-1); + } } diff --git a/src/CreateCustomer.h b/src/CreateCustomer.h index cb425a1..a7fdbc8 100644 --- a/src/CreateCustomer.h +++ b/src/CreateCustomer.h @@ -2,5 +2,7 @@ #include #include #include +#include "CustomerProperties.h" int generateID(); void collectCustomerProperties(); +void writeCustomerPropertiesToFile(customer_t *);