Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define ABS(n) n >= 0 ? n : -n
- void my_itoa(int numb, char *s);
- void my_itoa_rec(int numb, char **s);
- void my_itoa_rec(int numb, char **s)
- {
- if (numb)
- my_itoa_rec(numb / 10, s);
- else
- {
- return;
- }
- int digit = numb % 10;
- digit = ABS(digit);
- **s = digit + '0';
- (*s)++;
- **s = '\0';
- return;
- }
- void my_itoa(int numb, char *s)
- {
- if (!numb)
- {
- s[0] = '0';
- s[1] = '\0';
- return;
- }
- if (numb < 0)
- *s++ = '-';
- my_itoa_rec(numb, &s);
- }
- int main (void)
- {
- int numb = INT_MAX;
- char s[256];
- my_itoa(numb, s);
- printf("%s\n", s);
- numb = INT_MIN;
- my_itoa(numb, s);
- printf("%s\n", s);
- numb = 0;
- my_itoa(numb, s);
- printf("%s\n", s);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement