Browse Source

Makefile: add norminette rule. Add 42 headers. itoa is now based on itoa_base. Enh itoa_base but doesn't fit with norm.

Moul 5 years ago
parent
commit
3e830f0078
5 changed files with 39 additions and 16 deletions
  1. 4 1
      Makefile
  2. 7 2
      ft_itoa.c
  3. 15 11
      ft_itoa_base.c
  4. 1 1
      ft_strnew.c
  5. 12 1
      sort_int_tab.c

+ 4 - 1
Makefile

@@ -6,7 +6,7 @@
 #    By: mazimi <mazimi@student.42.fr>              +#+  +:+       +#+         #
 #                                                 +#+#+#+#+#+   +#+            #
 #    Created: 2014/11/05 11:09:24 by mazimi            #+#    #+#              #
-#    Updated: 2015/09/25 13:48:00 by mazimi           ###   ########.fr        #
+#    Updated: 2015/12/17 15:23:53 by mazimi           ###   ########.fr        #
 #                                                                              #
 # **************************************************************************** #
 
@@ -102,3 +102,6 @@ fclean: clean
 	@echo "Lifbt: fclean: library deleted."
 
 re: fclean all
+
+norm:
+	@norminette $(SRC) libft.h

+ 7 - 2
ft_itoa.c

@@ -6,12 +6,17 @@
 /*   By: mazimi <mazimi@student.42.fr>              +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2014/12/09 14:15:57 by mazimi            #+#    #+#             */
-/*   Updated: 2015/03/04 12:00:31 by mazimi           ###   ########.fr       */
+/*   Updated: 2015/12/17 14:52:17 by mazimi           ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
 #include "libft.h"
 
+char	*ft_itoa(int c)
+{
+	return (ft_itoa_base(c, 10));
+}
+/*
 static char		*ft_turn(char *src, int lon)
 {
 	char	*dest;
@@ -68,4 +73,4 @@ char			*ft_itoa(int c)
 		str[i - 1] = '-';
 	dst = ft_turn(str, lon);
 	return (dst);
-}
+}*/

+ 15 - 11
ft_itoa_base.c

@@ -1,3 +1,15 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   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)
@@ -18,23 +30,15 @@ char	*ft_itoa_base(int value, int base)
 		len++;
 	}
 	len = (nbr < 0) ? len + 1 : len;
-	str = (char*)malloc(sizeof(char) * (len + 1));
+	str = ft_strnew(len);
 	str[0] = '-';
 	i = (nbr < 0) ? 0 : -1;
 	nbr = (nbr < 0) ? -nbr : nbr;
 	while (++i < len)
 	{
 		c = nbr / mult;
-		if (0 <= c && c <= 9)
-		{
-			str[i] = c + 48;
-			nbr = nbr - c * mult;
-		}
-		if (9 < c && c <= 15)
-		{
-			str[i] = c + 55;
-			nbr = nbr - c * mult;
-		}
+		str[i] = (0 <= c && c <= 9) ? c + 48 : c + 55;
+		nbr = nbr - c * mult;
 		mult = mult / base;
 	}
 	str[i] = '\0';

+ 1 - 1
ft_strnew.c

@@ -6,7 +6,7 @@
 /*   By: mazimi <mazimi@student.42.fr>              +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2014/11/10 14:26:38 by mazimi            #+#    #+#             */
-/*   Updated: 2015/01/27 00:57:52 by mazimi           ###   ########.fr       */
+/*   Updated: 2015/12/17 15:24:41 by mazimi           ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 

+ 12 - 1
sort_int_tab.c

@@ -1,8 +1,19 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   sort_int_tab.c                                     :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: mazimi <marvin@42.fr>                      +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2015/12/17 15:27:13 by mazimi            #+#    #+#             */
+/*   Updated: 2015/12/17 15:52:46 by mazimi           ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
 #include "libft.h"
 
 void	sort_int_tab(int *tab, unsigned int size)
 {
-
 	int				tmp;
 	int				sorted;
 	unsigned int	i;