add TO_UNITS_ON_THE_END and FROM_UNITS_ON_THE_END
* add reverse_string() * number variable instead of number_first/number_last * add flags TO_UNITS_ON_THE_END and FROM_UNITS_ON_THE_END Signed-off-by: Daniel Santos <dacs.git@brilhante.top>
This commit is contained in:
parent
ef7e6f99a2
commit
dcc93c0ba6
55
numericx.c
55
numericx.c
|
@ -10,6 +10,18 @@
|
|||
#define DEBUG false
|
||||
#endif
|
||||
|
||||
#ifdef TO_UNITS_ON_THE_END
|
||||
#define TO_UNITS_ON_THE_END true
|
||||
#else
|
||||
#define TO_UNITS_ON_THE_END false
|
||||
#endif
|
||||
|
||||
#ifdef FROM_UNITS_ON_THE_END
|
||||
#define FROM_UNITS_ON_THE_END true
|
||||
#else
|
||||
#define FROM_UNITS_ON_THE_END false
|
||||
#endif
|
||||
|
||||
typedef struct NumeralPtr
|
||||
{
|
||||
char const* symbol;
|
||||
|
@ -83,15 +95,43 @@ is_the_same(numeral_ptr* numeral, char* number_arg)
|
|||
void
|
||||
print_numeral(numeral_ptr* numeral)
|
||||
{
|
||||
while( !(numeral == NULL) )
|
||||
if( TO_UNITS_ON_THE_END )
|
||||
{
|
||||
printf("%c", *(numeral->symbol));
|
||||
numeral = numeral->next;
|
||||
while( !(numeral->next == NULL) )
|
||||
numeral = numeral->next;
|
||||
|
||||
while( !(numeral == NULL) )
|
||||
{
|
||||
printf("%c", *(numeral->symbol));
|
||||
numeral = numeral->previous;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while( !(numeral == NULL) )
|
||||
{
|
||||
printf("%c", *(numeral->symbol));
|
||||
numeral = numeral->next;
|
||||
}
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void
|
||||
reverse_string(char* string)
|
||||
{
|
||||
char tmp;
|
||||
char* string_end = string + strlen(string);
|
||||
|
||||
while ( --string_end > string )
|
||||
{
|
||||
tmp = *string;
|
||||
*string++ = *string_end;
|
||||
*string_end = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char* argv[])
|
||||
{
|
||||
|
@ -121,15 +161,17 @@ main(int argc, char* argv[])
|
|||
char* to_first = to;
|
||||
char* to_last = to + (strlen(to) - 1);
|
||||
|
||||
char* number_first = number;
|
||||
char* number_last = number + (strlen(number) - 1);
|
||||
if( FROM_UNITS_ON_THE_END )
|
||||
{
|
||||
reverse_string(number);
|
||||
}
|
||||
|
||||
/* initializing counting and result */
|
||||
numeral_ptr* counting = new_digit(NULL, from_first);
|
||||
numeral_ptr* result = new_digit(NULL, to_first);
|
||||
|
||||
/* increments until it finishes */
|
||||
while( !is_the_same(counting, number_first) )
|
||||
while( !is_the_same(counting, number) )
|
||||
{
|
||||
if(DEBUG)
|
||||
{
|
||||
|
@ -152,6 +194,7 @@ main(int argc, char* argv[])
|
|||
print_numeral(counting);
|
||||
printf("result: ");
|
||||
}
|
||||
|
||||
print_numeral(result);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
|
|
Loading…
Reference in New Issue