#include "../libc/include/stdio.h" #include "../libc/include/string.h" /*extern void writestring(const char* __s); extern char* getstring(void);*/ void print_uint(uint32_t value) { char buffer[11]; int i = 0; do { buffer[i++] = '0' + (value % 10); value /= 10; } while (value > 0); while (i--) { writechar(buffer[i]); } } int main(void) { while (1) { writestring("command: "); char* istr; int rv = getstring(istr); if (!istr) { writestring("\nERROR: getstring returned NULL\n"); break; } if (rv != 0) { writestring("\nERROR: getstring did not return 0\n"); break; } size_t len = strlen(istr); if (len > 0 && istr[len - 1] == '\n') { istr[len - 1] = '\0'; } writestring("you entered: "); writestring(istr); writestring(" ASCII -> "); for (size_t n = 0; n < (len + 1); n++) { print_uint(istr[n]); writechar(' '); } writechar('\n'); if (strcmp(istr, "exit") == 0) { return 0; } } return 0; }