mirror of
https://github.com/logicog/RTLPlayground.git
synced 2026-08-30 14:52:51 +08:00
httpd: fix itoa_html() does not print the middle zero.
when the input is 100. the first zero is not printed because t = 0 and skip printing. So the output is "10" instead of "100".
This commit is contained in:
+10
-4
@@ -67,14 +67,20 @@ void byte_to_html(uint8_t val)
|
||||
} while(cnt);
|
||||
}
|
||||
|
||||
|
||||
/* Converts a uint8_t to raw string.
|
||||
Suppress leading zeros.
|
||||
*/
|
||||
void itoa_html(uint8_t v)
|
||||
{
|
||||
uint8_t t = (v / 100) % 10;
|
||||
if (t)
|
||||
uint8_t t = (v / 100);
|
||||
// when print_zeros is not zero, we know that a non-zero number has printed.
|
||||
// That have to print all the next numbers.
|
||||
uint8_t print_zeros = t;
|
||||
if (print_zeros)
|
||||
char_to_html('0' + t);
|
||||
t = (v / 10) % 10;
|
||||
if (t)
|
||||
print_zeros |= t;
|
||||
if (print_zeros)
|
||||
char_to_html('0' + t);
|
||||
char_to_html('0' + (v % 10));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user