From c9b6b9a5ca082fe7c1b6f58d7713f785a9eb6a5c Mon Sep 17 00:00:00 2001 From: Martial Simon Date: Mon, 15 Sep 2025 01:08:27 +0200 Subject: add: graphs et rushs --- rushs/tinyprintf/my_itoa/my_itoa.c | 38 ++++++++++++++++++++++++++++++++++++++ rushs/tinyprintf/my_itoa/my_itoa.h | 6 ++++++ 2 files changed, 44 insertions(+) create mode 100644 rushs/tinyprintf/my_itoa/my_itoa.c create mode 100644 rushs/tinyprintf/my_itoa/my_itoa.h (limited to 'rushs/tinyprintf/my_itoa') diff --git a/rushs/tinyprintf/my_itoa/my_itoa.c b/rushs/tinyprintf/my_itoa/my_itoa.c new file mode 100644 index 0000000..cbb6f73 --- /dev/null +++ b/rushs/tinyprintf/my_itoa/my_itoa.c @@ -0,0 +1,38 @@ +#include "my_itoa.h" + +char *my_itoa(int value, char *s) +{ + if (value == 0) + { + s[0] = '0'; + s[1] = '\0'; + return s; + } + char *head = s; + if (value < 0) + { + s[0] = '-'; + s++; + value = -value; + } + + // count numbers + int t = value; + int n = 0; + while (t > 0) + { + t /= 10; + n++; + } + + // n = number count + s[n] = '\0'; + n--; + for (; n >= 0; n--) + { + s[n] = value % 10 + '0'; + value /= 10; + } + + return head; +} diff --git a/rushs/tinyprintf/my_itoa/my_itoa.h b/rushs/tinyprintf/my_itoa/my_itoa.h new file mode 100644 index 0000000..8e84c72 --- /dev/null +++ b/rushs/tinyprintf/my_itoa/my_itoa.h @@ -0,0 +1,6 @@ +#ifndef MY_ITOA_H +#define MY_ITOA_H + +char *my_itoa(int value, char *s); + +#endif /* ! MY_ITOA_H */ -- cgit v1.2.3