long integer number provided by the user and displays it to the filestream stream as an integer. This requires separating the number into individual characters, converting each character into its digit value, and then displaying the resul
I'm trying to write a decout function that seperates the given long number to individual characters and the converting each character into its digit value and displaying the result. I got the algorithm done. here's what I have
Code:
void decout (unsigned long number, FILE * stream)
{
int last_digit, second_digit, first_digit, exit_loop, COUNT;
long digit_count = 0;
while(digit_count == COUNT)
{
last_digit = number % 10 + '0'; //last digit
//add number to array
last_digit = number / 10;
second_digit = last_digit % 10 +'0' //second digit
//add number to array
first_digit = last_digit / 10;
first_digit % 10 = exit_loop;
exit_loop = COUNT;
}
}
digits, is declared as const char digits[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; by the way.
I know there is a flaw to the algorithm but I feel like it's just a constant repetition over and over. How will I just summarize the algorithm so it works for all cases and not just three digits as my algorithm does?
Thank you so much!