diff options
| author | EmulatedSeasons <89668582+EmulatedSeasons@users.noreply.github.com> | 2024-05-31 21:08:22 -0400 |
|---|---|---|
| committer | EmulatedSeasons <89668582+EmulatedSeasons@users.noreply.github.com> | 2024-05-31 21:08:22 -0400 |
| commit | 1bd17dce9a8297f86f3bb34b3f440490b601eca6 (patch) | |
| tree | 9741c7c99e9f5675dc08b26b005eb1f6047623f2 /libc | |
| parent | 4956918086a85031bb47b28e868c0ff8e6cc8f95 (diff) | |
started working on pmm and fixed printf doing weird things to the
numbers
Diffstat (limited to 'libc')
| -rw-r--r-- | libc/printf.c | 26 |
1 files changed, 17 insertions, 9 deletions
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';
|
