|
@@ -12,67 +12,60 @@
|
|
|
|
|
|
#include "../libft.h"
|
|
|
|
|
|
-char *ft_itoa(int c)
|
|
|
+static char *ft_turn(char *src, int lon)
|
|
|
{
|
|
|
- return (ft_itoa_base(c, 10));
|
|
|
+ char *dest;
|
|
|
+ int i;
|
|
|
+ int j;
|
|
|
+
|
|
|
+ dest = ft_strnew(lon);
|
|
|
+ j = lon;
|
|
|
+ i = -1;
|
|
|
+ while (++i < lon)
|
|
|
+ dest[i] = src[--j];
|
|
|
+ return (dest);
|
|
|
+}
|
|
|
+
|
|
|
+static int intlen(int c)
|
|
|
+{
|
|
|
+ int i;
|
|
|
+ int lon;
|
|
|
+
|
|
|
+ i = 1;
|
|
|
+ if (c < 0)
|
|
|
+ i++;
|
|
|
+ lon = c;
|
|
|
+ while (lon >= 10 || lon <= -10)
|
|
|
+ {
|
|
|
+ lon = lon / 10;
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ return (i);
|
|
|
}
|
|
|
|
|
|
-/*
|
|
|
-**static char *ft_turn(char *src, int lon)
|
|
|
-**{
|
|
|
-** char *dest;
|
|
|
-** int i;
|
|
|
-** int j;
|
|
|
-**
|
|
|
-** dest = ft_strnew(lon);
|
|
|
-** j = lon;
|
|
|
-** i = -1;
|
|
|
-** while (++i < lon)
|
|
|
-** dest[i] = src[--j];
|
|
|
-** return (dest);
|
|
|
-**}
|
|
|
-**
|
|
|
-**static int intlen(int c)
|
|
|
-**{
|
|
|
-** int i;
|
|
|
-** int lon;
|
|
|
-**
|
|
|
-** i = 1;
|
|
|
-** if (c < 0)
|
|
|
-** i++;
|
|
|
-** lon = c;
|
|
|
-** while (lon >= 10 || lon <= -10)
|
|
|
-** {
|
|
|
-** lon = lon / 10;
|
|
|
-** i++;
|
|
|
-** }
|
|
|
-** return (i);
|
|
|
-**}
|
|
|
-**
|
|
|
-**char *ft_itoa(int c)
|
|
|
-**{
|
|
|
-** int lon;
|
|
|
-** char *str;
|
|
|
-** char *dst;
|
|
|
-** int cc;
|
|
|
-** int i;
|
|
|
-**
|
|
|
-** if (c == -2147483648)
|
|
|
-** return (ft_strdup("-2147483648"));
|
|
|
-** cc = c;
|
|
|
-** lon = intlen(c);
|
|
|
-** str = ft_strnew(lon);
|
|
|
-** if (c < 0)
|
|
|
-** c = -c;
|
|
|
-** i = -1;
|
|
|
-** while (++i < lon)
|
|
|
-** {
|
|
|
-** str[i] = (c % 10) + 48;
|
|
|
-** c = c / 10;
|
|
|
-** }
|
|
|
-** if (cc < 0)
|
|
|
-** str[i - 1] = '-';
|
|
|
-** dst = ft_turn(str, lon);
|
|
|
-** return (dst);
|
|
|
-**}
|
|
|
-*/
|
|
|
+char *ft_itoa(int c)
|
|
|
+{
|
|
|
+ int lon;
|
|
|
+ char *str;
|
|
|
+ char *dst;
|
|
|
+ int cc;
|
|
|
+ int i;
|
|
|
+
|
|
|
+ if (c == -2147483648)
|
|
|
+ return (ft_strdup("-2147483648"));
|
|
|
+ cc = c;
|
|
|
+ lon = intlen(c);
|
|
|
+ str = ft_strnew(lon);
|
|
|
+ if (c < 0)
|
|
|
+ c = -c;
|
|
|
+ i = -1;
|
|
|
+ while (++i < lon)
|
|
|
+ {
|
|
|
+ str[i] = (c % 10) + 48;
|
|
|
+ c = c / 10;
|
|
|
+ }
|
|
|
+ if (cc < 0)
|
|
|
+ str[i - 1] = '-';
|
|
|
+ dst = ft_turn(str, lon);
|
|
|
+ return (dst);
|
|
|
+}
|