A poorly written OS for the x86 arch. (WIP)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
eOS/lib/conv.c

18 lines
518 B

3 years ago
#include "conv.h"
3 years ago
#include "../drivers/vga.h"
3 years ago
3 years ago
char* int_to_str(int i, char* buf) {
ulong num = (ulong)i; // convert to ulong
3 years ago
uint len = ulong_len(num); // number of digits
3 years ago
*(buf+len) = '\0'; // add a "end-of-string" at the end
3 years ago
int j;
for(j = 0; j < len; j++) // iterate over each digit and assign it to the buffer
// super dangerous memory write
3 years ago
println("char!", DEFAULT_COLOR);
*(buf+j) = (char)(ndigit(num, len-1-j) + ASCII_OFFSET); // apply the ascii offset so that i becomes a char
3 years ago
return buf;
3 years ago
}