From 3c72511444dedb9baf0b14f9ae48fc4deef304d6 Mon Sep 17 00:00:00 2001 From: cy384 Date: Thu, 23 Jul 2020 19:45:01 -0400 Subject: [PATCH] add quick simple integer print function --- ssheven-console.c | 16 ++++++++++++++++ ssheven-console.h | 1 + 2 files changed, 17 insertions(+) diff --git a/ssheven-console.c b/ssheven-console.c index 3f49215..bf3bc67 100644 --- a/ssheven-console.c +++ b/ssheven-console.c @@ -107,6 +107,22 @@ void print_char(char c) } } +void print_int(int d) +{ + char itoc[] = {'0','1','2','3','4','5','6','7','8','9'}; + + char buffer[12] = {0}; + int i = 10; + + for (; d > 0; i--) + { + buffer[i] = itoc[d % 10]; + d /= 10; + } + + print_string(buffer+i+1); +} + void print_string_i(const char* c) { print_string(c); diff --git a/ssheven-console.h b/ssheven-console.h index 253442e..036ac88 100644 --- a/ssheven-console.h +++ b/ssheven-console.h @@ -22,6 +22,7 @@ int is_printable(char c); void print_char(char c); void print_string(const char* c); void print_string_i(const char* c); +void print_int(int d); void set_window_title(WindowPtr w, const char* c_name);