From 6ad040483c1bed1f321aab03230b9ded91020fb8 Mon Sep 17 00:00:00 2001 From: fdai7207 Date: Mon, 6 Feb 2023 19:35:59 +0100 Subject: [PATCH] refactoring: removed unnecessary lines and changed variables to constants in the storeEmployeeData() given that the function doesnt modify them. --- src/createEmployeeAccount.c | 36 +++++++++++++----------------------- src/createEmployeeAccount.h | 4 ++-- 2 files changed, 15 insertions(+), 25 deletions(-) diff --git a/src/createEmployeeAccount.c b/src/createEmployeeAccount.c index 791a92a..47c6eb9 100644 --- a/src/createEmployeeAccount.c +++ b/src/createEmployeeAccount.c @@ -61,7 +61,9 @@ int StringLengthCounter(char* string) return characterCounter; } -bool storeEmployeeData(char *name,char *lastName,char *adress,char *phoneNumber) +/*changed the string parameters to constants as an indicator that the function doesnt modify them*/ + +bool storeEmployeeData(const char *name,const char *lastName,const char *adress,const char *phoneNumber) { FILE* employeesDatalist; employeesDatalist = fopen("src/employeesData.txt","a"); @@ -106,66 +108,54 @@ bool createNewEmployee(char* employeeId, char* employeePassword) void getNewEmployeeCredentials() { - employeedata *data; - data = (employeedata*)malloc(sizeof(employeedata)); + employeedata *data = (employeedata*)malloc(sizeof(employeedata)); const int maxLength = 21; char employeeId[maxLength]; - const int minPasswordLength = 5; - char employeePassword[maxLength]; char passwordVerfication[maxLength]; printf("please enter your wished Id :\n"); - /*Added the regular expression [^\n] so that the string keep on getting read until a newline '\n' is found*/ - scanf(" %[^\n]s",employeeId); - employeeId[maxLength] = '\0'; printf("\nplease enter your wished Password :\n"); - scanf("%s",employeePassword); - employeePassword[strlen(employeePassword)] = '\0'; printf("\nplease confirm your Password :\n"); - scanf("%s",passwordVerfication); - passwordVerfication[strlen(employeePassword)] = '\0'; if(verifyPassword(passwordVerfication,employeePassword) && isValidPassword(employeePassword,minPasswordLength) && isValidEmployeeID(employeeId,maxLength)) { printf("\n\nplease enter your first name\n"); - scanf("%s",data->firstName); printf("\n\nplease enter your last name\n"); - scanf("%s",data->lastName); printf("\n\nplease enter your adress\n"); - - scanf("%s",data->adress); + scanf("%s",data->address); printf("\n\nplease enter your Phone number\n"); - scanf("%s",data->phoneNumber); - createNewEmployee(employeeId,employeePassword) ? printf("\n\n Account created successfully !\n\n") : printf("\n\n Could not create the Account please contact an employee of clearance 1 !\n\n"); + createNewEmployee(employeeId,employeePassword) ? + printf("\n\n Account created successfully !\n\n") : + printf("\n\n Could not create the Account please contact an employee of clearance 1 !\n\n"); - storeEmployeeData(data->firstName,data->lastName,data->adress,data->phoneNumber); + storeEmployeeData(data->firstName,data->lastName,data->address,data->phoneNumber); } else { - printf("\n\nError! one of these conditions is not met in your input\n\n"); - printf("\n-the entered password should be at least 5 characters long and should contain at least 1 digit, 1 alphabet and 1 symbol!\n"); - printf("\n-the entered ID should contain a maximum of 20 letters!\n"); - printf("\n-the verification password should match with the entered password.\n"); + printf("\nError! one of these conditions is not met in your input.\n"); + printf("\n-The entered password should be at least 5 characters long and should contain at least 1 digit, 1 alphabet and 1 symbol.\n"); + printf("\n-The entered ID should contain a maximum of 20 letters.\n"); + printf("\n-The verification password should match with the entered password.\n"); } } diff --git a/src/createEmployeeAccount.h b/src/createEmployeeAccount.h index 181228c..ca94af0 100644 --- a/src/createEmployeeAccount.h +++ b/src/createEmployeeAccount.h @@ -11,7 +11,7 @@ struct employeesInformations { char firstName[15]; char lastName[15]; - char adress[20]; + char address[20]; char phoneNumber[15]; }; typedef struct employeesInformations employeedata; @@ -20,7 +20,7 @@ bool isValidEmployeeID(const char* employee, int maximumLength); bool isValidPassword( char* password, int minimumLength); bool createNewEmployee(char* employeeId, char* employeePassword); bool verifyPassword(char* enteredPassword,char* passwordConfirmation); -bool storeEmployeeData(char *name,char *lastName,char *adress,char *phoneNumber); +bool storeEmployeeData(const char *name,const char *lastName,const char *adress,const char *phoneNumber); int StringLengthCounter(char* string);