diff --git a/src/CreateCustomer.c b/src/CreateCustomer.c index 41696d8..5212eab 100644 --- a/src/CreateCustomer.c +++ b/src/CreateCustomer.c @@ -1,5 +1,4 @@ #include "CreateCustomer.h" -#include "CustomerProperties.h" int generateID() { @@ -76,4 +75,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 *);