diff --git a/src/createCustomer.c b/src/createCustomer.c index e3a9920..7dd6aa2 100644 --- a/src/createCustomer.c +++ b/src/createCustomer.c @@ -18,7 +18,7 @@ void collectCustomerProperties() int letterCounter = 0; int letterMaximum = 15; char userInput=' '; - bool inputTooLong = false; + bool inputTooLong = false, foundComma = false; printf("To create a new user, enter the information required below.\n"); printf("Enter forename (max. 15 letters):\n"); while(letterCounter=letterMaximum){ + inputTooLong = true; + break; + } + } + if(inputTooLong){ + puts("Input too long."); + exit(-1); + //call errorMessage(-10); + }else{ + if(!foundComma){ + *(balanceCharacters+letterCounter) = '.'; + ++letterCounter; + *(balanceCharacters+letterCounter) = '0'; + ++letterCounter; + } + *(balanceCharacters+letterCounter) = '\0'; + } + if(!everyCharacterIsDigit(balanceCharacters)){ + puts("You have entered a character that is not a number. This is not allowed. Aborting!"); + exit(-1); + } + instance.balance = balanceToDouble(balanceCharacters); printf("Account successfully created. Your ID is: %d. Note it somewhere!\n",instance.ID); customer_t *referenceToCustomerInstance = &instance; writeCustomerPropertiesToFile(referenceToCustomerInstance); diff --git a/src/customerProperties.h b/src/customerProperties.h index 0e3bb72..39661d1 100644 --- a/src/customerProperties.h +++ b/src/customerProperties.h @@ -6,6 +6,6 @@ typedef struct Customer char *IDAsString; char *password; char *forename, *surname; - float balance; + double balance; }customer_t; #endif diff --git a/src/error.c b/src/error.c index 68294c1..dc22300 100644 --- a/src/error.c +++ b/src/error.c @@ -46,12 +46,12 @@ int errorMessage(int errorCode) exit(-1); break; case -10: - puts("You have entered a digit for your forename. This is not allowed. Aborting!"); + puts("You have entered an invalid character [ä,ö,ü, special characters] 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!"); + puts("You have entered an invalid character [ä,ö,ü, special characters] for your surname. This is not allowed. Aborting!"); returnValue = -11; exit(-1); break; diff --git a/src/helperFunctions.c b/src/helperFunctions.c index 3b0fde0..c3b2513 100644 --- a/src/helperFunctions.c +++ b/src/helperFunctions.c @@ -71,7 +71,7 @@ bool everyCharacterIsDigit(char *string) { bool onlyDigits = true; for(int i=0;*(string+i)!='\0';++i){ - if(*(string+i)<'0'||*(string+i)>'9'){ + if( !(*(string+i)>='0'&&*(string+i)<='9') && *(string+i)!='.'){ onlyDigits = false; break; } @@ -82,7 +82,7 @@ bool everyCharacterIsDigit(char *string) bool isLetterOfAlphabet(char *string){ bool everyCharIsInAlphabet = true; for(int i=0;*(string+i)!='\0';++i){ - if( !(*(string+i)>='A'&&*(string+i)<='Z') && !(*(string+i)>='a'&&*(string+i)<='z')){ + if(!(*(string+i)>='A'&&*(string+i)<='Z') && !(*(string+i)>='a'&&*(string+i)<='z')){ everyCharIsInAlphabet = false; break; } diff --git a/test/test_helperFunctions.c b/test/test_helperFunctions.c index 9287351..da8bc7f 100644 --- a/test/test_helperFunctions.c +++ b/test/test_helperFunctions.c @@ -2,7 +2,6 @@ #include #include #include -#include "unity_config.h" #include "../src/helperFunctions.c" void test_isLetterOfAlphabet()