Browse Source

[norm] remove itoa_base which is now on 'itoa_base' branch.

Moul 2 years ago
parent
commit
f25ce931d1
4 changed files with 54 additions and 109 deletions
  1. 0 1
      Makefile
  2. 0 1
      libft.h
  3. 54 61
      src/ft_itoa.c
  4. 0 46
      src/ft_itoa_base.c

+ 0 - 1
Makefile

@@ -63,7 +63,6 @@ ft_strsplit.c \
 ft_tabsize.c \
 ft_tabdel.c \
 ft_itoa.c \
-ft_itoa_base.c \
 ft_strtrim.c \
 ft_putchar.c \
 ft_putstr.c \

+ 0 - 1
libft.h

@@ -79,7 +79,6 @@ char				**ft_strsplit(char const *s, char c);
 int					ft_tabsize(char **tab);
 void				ft_tabdel(char **tabe);
 char				*ft_itoa(int n);
-char				*ft_itoa_base(int value, int base);
 void				ft_putchar(char c);
 void				ft_putstr(char const *s);
 void				ft_putendl(char const *s);

+ 54 - 61
src/ft_itoa.c

@@ -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);
+}

+ 0 - 46
src/ft_itoa_base.c

@@ -1,46 +0,0 @@
-/* ************************************************************************** */
-/*                                                                            */
-/*                                                        :::      ::::::::   */
-/*   ft_itoa_base.c                                     :+:      :+:    :+:   */
-/*                                                    +:+ +:+         +:+     */
-/*   By: mazimi <marvin@42.fr>                      +#+  +:+       +#+        */
-/*                                                +#+#+#+#+#+   +#+           */
-/*   Created: 2015/12/17 15:24:28 by mazimi            #+#    #+#             */
-/*   Updated: 2015/12/17 15:56:31 by mazimi           ###   ########.fr       */
-/*                                                                            */
-/* ************************************************************************** */
-
-#include "../libft.h"
-
-char	*ft_itoa_base(int value, int base)
-{
-	char	*str;
-	int		mult;
-	int		len;
-	int		i;
-	long	nbr;
-	char	c;
-
-	nbr = value;
-	mult = 1;
-	len = 1;
-	while (nbr / mult >= base || nbr / mult <= -base)
-	{
-		mult = mult * base;
-		len++;
-	}
-	len = (nbr < 0) ? len + 1 : len;
-	str = ft_strnew(len);
-	str[0] = '-';
-	i = (nbr < 0) ? 0 : -1;
-	nbr = (nbr < 0) ? -nbr : nbr;
-	while (++i < len)
-	{
-		c = nbr / mult;
-		str[i] = (0 <= c && c <= 9) ? c + 48 : c + 55;
-		nbr = nbr - c * mult;
-		mult = mult / base;
-	}
-	str[i] = '\0';
-	return (str);
-}