Browse Source

Implementation of writeCustomerPropertiesToFile()

remotes/origin/feature/customer-creation
fdai7057 2 years ago
parent
commit
1450f66117
  1. 20
      src/CreateCustomer.c
  2. 2
      src/CreateCustomer.h

20
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);
}
}

2
src/CreateCustomer.h

@ -2,5 +2,7 @@
#include <stdlib.h>
#include <stdbool.h>
#include <time.h>
#include "CustomerProperties.h"
int generateID();
void collectCustomerProperties();
void writeCustomerPropertiesToFile(customer_t *);
Loading…
Cancel
Save