Browse Source

refactoring: changed some variabales names in createEmployeeAccount.c for better readability.

remotes/origin/feature/employees-infos-access
fdai7207 2 years ago
parent
commit
25b42cd0c0
  1. 28
      src/createEmployeeAccount.c
  2. 2
      src/createEmployeeAccount.h

28
src/createEmployeeAccount.c

@ -17,18 +17,18 @@ int StringLengthCounter(char* string)
} }
bool isValidEmployeeID(char* employeeId, int maximumLength)
bool isValidEmployeeID(const char* employeeId, int maximumStringLength)
{ {
int employeeIdLength = strlen(employeeId); int employeeIdLength = strlen(employeeId);
int i;
for(i=0;i<employeeIdLength;i++)
for(int i=0;i<employeeIdLength;i++)
{ {
if(employeeId[i]==' ') if(employeeId[i]==' ')
{ {
return false; return false;
} }
} }
return employeeIdLength <= maximumLength ;
return employeeIdLength <= maximumStringLength ;
} }
bool createNewEmployee(char* employeeId, char* employeePassword) bool createNewEmployee(char* employeeId, char* employeePassword)
@ -54,25 +54,27 @@ bool createNewEmployee(char* employeeId, char* employeePassword)
void getNewEmployeeCredentials() void getNewEmployeeCredentials()
{ {
int newEmployeeIdlength = 21;
char newEmployeeId[newEmployeeIdlength];
char newEmployeePassword[newEmployeeIdlength];
const int employeeIdlength = 21;
char employeeId[employeeIdlength];
char employeePassword[employeeIdlength];
printf("please enter your wished Id :\n"); printf("please enter your wished Id :\n");
scanf(" %[^\n]s",newEmployeeId);
/*Added the regular expression [^\n] so that the string keep on getting read until a newline '\n' is found*/
scanf(" %[^\n]s",employeeId);
newEmployeeId[newEmployeeIdlength] = '\0';
employeeId[employeeIdlength] = '\0';
printf("\nplease enter your wished Password :\n"); printf("\nplease enter your wished Password :\n");
scanf("%s",newEmployeePassword);
scanf("%s",employeePassword);
newEmployeePassword[newEmployeeIdlength] = '\0';
employeePassword[employeeIdlength] = '\0';
if(isValidEmployeeID(newEmployeeId,newEmployeeIdlength))
if(isValidEmployeeID(employeeId,employeeIdlength))
{ {
createNewEmployee(newEmployeeId,newEmployeePassword) ? 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");
} }
else else

2
src/createEmployeeAccount.h

@ -6,7 +6,7 @@
#include<stdbool.h> #include<stdbool.h>
#include<string.h> #include<string.h>
bool isValidEmployeeID(char* employee, int maximumLength);
bool isValidEmployeeID(const char* employee, int maximumLength);
bool createNewEmployee(char* employeeId, char* employeePassword); bool createNewEmployee(char* employeeId, char* employeePassword);
int StringLengthCounter(char* string); int StringLengthCounter(char* string);

Loading…
Cancel
Save