@ -11,13 +11,13 @@ char *to_string(int number)
}
else
{
int cpy = number , len = 0 ;
while ( number > 0 ) {
int cpy = number , len = 0 ;
while ( number > 0 ) {
+ + len ;
number / = 10 ;
}
char * str = calloc ( len + 1 , sizeof ( char ) ) ;
for ( int i = 0 , j = len - 1 ; i < len ; + + i , - - j ) {
}
char * str = calloc ( len + 1 , sizeof ( char ) ) ;
for ( int i = 0 , j = len - 1 ; i < len ; + + i , - - j ) {
* ( str + j ) = ' 0 ' + ( cpy % 10 ) ;
cpy / = 10 ;
}
@ -26,18 +26,19 @@ char *to_string(int number)
}
}
char * generateCheckString ( int ID , char * p assword)
char * generateCheckString ( int customer ID, char * customerP assword)
{
char * IDString = to_string ( ID ) ;
/*The purpose of this function is to generate a string that is needed when a user wants to login.
* This string is searched for in the customer - data file and if it is found , the login is successful .
* This function is needed when a new user is created because then it is written in the file for the first time .
* The format of the string is : [ ID ] = [ PASSWORD ] */
char * IDString = to_string ( customerID ) ;
int IDLength = strlen ( IDString ) ;
int passwordLength = strlen ( password ) ;
/*the checkString has this form: ID=password, so in order to calculate its length the length of the ID, one byte for the =, the length of the password and
* one byte for ' \0 ' are needed . */
int passwordLength = strlen ( customerPassword ) ;
int checkStringLength = IDLength + 1 + passwordLength + 1 ;
char * checkString = calloc ( checkStringLength , sizeof ( char ) ) ;
checkString = strcat ( IDString , " = " ) ;
checkString = strcat ( checkString , p assword) ;
checkString = strcat ( checkString , customerP assword) ;
* ( checkString + checkStringLength ) = ' \0 ' ;
return checkString ;
}