summaryrefslogtreecommitdiff
path: root/rushs/tinyprintf/my_itoa/my_itoa.c
diff options
context:
space:
mode:
authorMartial Simon <msimon_fr@hotmail.com>2025-09-15 01:08:27 +0200
committerMartial Simon <msimon_fr@hotmail.com>2025-09-15 01:08:27 +0200
commitc9b6b9a5ca082fe7c1b6f58d7713f785a9eb6a5c (patch)
tree3e4f42f93c7ae89a364e4d51fff6e5cec4e55fa9 /rushs/tinyprintf/my_itoa/my_itoa.c
add: graphs et rushs
Diffstat (limited to 'rushs/tinyprintf/my_itoa/my_itoa.c')
-rw-r--r--rushs/tinyprintf/my_itoa/my_itoa.c38
1 files changed, 38 insertions, 0 deletions
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;
+}