Browse Source

Modified error handling. The error for invalid input for forename and surname when creating a new customer account is caught.

remotes/origin/development
fdai7057 2 years ago
parent
commit
be8ceb2652
  1. 9
      src/createCustomer.c
  2. 10
      src/error.c

9
src/createCustomer.c

@ -31,10 +31,14 @@ void collectCustomerProperties()
} }
if(inputTooLong){ if(inputTooLong){
errorMessage(-7); errorMessage(-7);
}else{
}
else{
*(instance.forename+letterCounter) = '\0'; *(instance.forename+letterCounter) = '\0';
letterCounter = 0; letterCounter = 0;
} }
if(!isLetterOfAlphabet(instance.forename)){
errorMessage(-10);
}
printf("Enter surname (max. 15 letters):\n"); printf("Enter surname (max. 15 letters):\n");
while(letterCounter<letterMaximum && (userInput=getchar())!='\n'){ while(letterCounter<letterMaximum && (userInput=getchar())!='\n'){
*(instance.surname+letterCounter) = userInput; *(instance.surname+letterCounter) = userInput;
@ -50,6 +54,9 @@ void collectCustomerProperties()
*(instance.surname+letterCounter) = '\0'; *(instance.surname+letterCounter) = '\0';
letterCounter = 0; letterCounter = 0;
} }
if(!isLetterOfAlphabet(instance.surname)){
errorMessage(-11);
}
printf("Enter password (max. 20 letters):\n"); printf("Enter password (max. 20 letters):\n");
while(letterCounter<letterMaximum && (userInput=getchar())!='\n'){ while(letterCounter<letterMaximum && (userInput=getchar())!='\n'){
*(instance.password+letterCounter) = userInput; *(instance.password+letterCounter) = userInput;

10
src/error.c

@ -45,6 +45,16 @@ int errorMessage(int errorCode)
returnValue = -9; returnValue = -9;
exit(-1); exit(-1);
break; break;
case -10:
puts("You have entered a digit for your forename. This is not allowed. Aborting!");
returnValue = -10;
exit(-1);
break;
case -11:
puts("You have entered a digit for your surname. This is not allowed. Aborting!");
returnValue = -11;
exit(-1);
break;
default: default:
puts("Error code unknown."); puts("Error code unknown.");
} }

Loading…
Cancel
Save