From 1bd17dce9a8297f86f3bb34b3f440490b601eca6 Mon Sep 17 00:00:00 2001 From: EmulatedSeasons <89668582+EmulatedSeasons@users.noreply.github.com> Date: Fri, 31 May 2024 21:08:22 -0400 Subject: started working on pmm and fixed printf doing weird things to the numbers --- libc/printf.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'libc/printf.c') diff --git a/libc/printf.c b/libc/printf.c index 72a4749..0bb5506 100644 --- a/libc/printf.c +++ b/libc/printf.c @@ -37,10 +37,14 @@ static const char* itoa(unsigned int num, char* str, unsigned int base) { } // reverse the string - for (int i = 0; i < cou; i++) { - char temp = str[i]; - str[i] = str[cou - i - 1]; - str[cou - 1] = temp; + size_t start = 0; + size_t end = cou - 1; + while (start < end) { + char temp = str[start]; + str[start] = str[end]; + str[end] = temp; + ++start; + --end; } str[cou] = '\0'; @@ -49,7 +53,7 @@ static const char* itoa(unsigned int num, char* str, unsigned int base) { // have no idea if there's a better way to do this. for %lx static const char* itoa_u64(unsigned long long num, char* str, int base) { - int cou = 0; // nt + size_t cou = 0; // nt if (num == 0) { // 0 str[cou] = '0'; @@ -71,10 +75,14 @@ static const char* itoa_u64(unsigned long long num, char* str, int base) { } // reverse the string - for (int i = 0; i < cou; i++) { - char temp = str[i]; - str[i] = str[cou - i - 1]; - str[cou - 1] = temp; + size_t start = 0; + size_t end = cou - 1; + while (start < end) { + char temp = str[start]; + str[start] = str[end]; + str[end] = temp; + ++start; + --end; } str[cou] = '\0'; -- cgit v1.2.3-70-g09d2