Check if number belongs to numerical system

* add is_valid_number()
 * check if number belongs to the 'from' numerical system

Signed-off-by: Daniel Santos <dacs.git@brilhante.top>
This commit is contained in:
Daniel Santos 2022-03-11 23:26:07 +00:00
parent ab849603a0
commit 06bb8994d4
1 changed files with 23 additions and 0 deletions

View File

@ -177,6 +177,22 @@ reverse_string(char* string)
}
}
bool is_valid_number(char* numeral_system, char *number)
{
/*
if( *number == '-' || *number == '+' )
++number;
*/
while( !(*number == '\0') )
{
if( strchr(numeral_system, *number) == NULL )
return false;
++number;
}
return true;
}
int
main(int argc, char* argv[])
{
@ -199,6 +215,13 @@ main(int argc, char* argv[])
/* Number variables to be converted */
char* number = argv[1];
/* Check if number belongs to it's numerical system */
if( !is_valid_number(from, number) )
{
fprintf(stderr, "error: %s.\n", strerror(EDOM));
exit(EDOM);
}
/* _first and _last variables */
char* from_first = from;
char* from_last = from + (strlen(from) - 1);