@ -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 & & ( userInput = getchar ( ) ) ! = ' \n ' ) {
@ -58,6 +58,7 @@ void collectCustomerProperties()
errorMessage ( - 11 ) ;
}
printf ( " Enter password (max. 20 letters): \n " ) ;
letterMaximum = 20 ;
while ( letterCounter < letterMaximum & & ( userInput = getchar ( ) ) ! = ' \n ' ) {
* ( instance . password + letterCounter ) = userInput ;
+ + letterCounter ;
@ -68,12 +69,40 @@ void collectCustomerProperties()
}
if ( inputTooLong ) {
errorMessage ( - 9 ) ;
}
} else {
* ( instance . password + letterCounter ) = ' \0 ' ;
letterCounter = 0 ;
printf ( " Enter balance: \n " ) ;
scanf ( " %f " , & instance . balance ) ;
}
letterCounter = 0 ;
printf ( " Enter balance (max. 10 digits): \n " ) ;
char * balanceCharacters = calloc ( 10 + 1 + 1 + 1 , sizeof ( char ) ) ;
letterMaximum = 10 ;
while ( letterCounter < letterMaximum & & ( userInput = getchar ( ) ) ! = ' \n ' ) {
* ( balanceCharacters + letterCounter ) = userInput ;
+ + letterCounter ;
if ( 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 ) ;