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:
parent
ab849603a0
commit
06bb8994d4
23
numericx.c
23
numericx.c
|
@ -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
|
int
|
||||||
main(int argc, char* argv[])
|
main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
|
@ -199,6 +215,13 @@ main(int argc, char* argv[])
|
||||||
/* Number variables to be converted */
|
/* Number variables to be converted */
|
||||||
char* number = argv[1];
|
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 */
|
/* _first and _last variables */
|
||||||
char* from_first = from;
|
char* from_first = from;
|
||||||
char* from_last = from + (strlen(from) - 1);
|
char* from_last = from + (strlen(from) - 1);
|
||||||
|
|
Loading…
Reference in New Issue