INCDIR = .
SRCDIR = .
# SOURCES = $(addprefix $(SRCDIR)/, ft_putchar.c ft_putstr.c ft_strcmp.c ft_strlen.c ft_swap.c)
-SOURCES = $(shell find $(SRCDIR) -name "*.c")
+SOURCES = $(shell find $(SRCDIR) -maxdepth 1 -name "*.c")
OBJECTS = $(SOURCES:.c=.o)
NAME = libft.a
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_abs.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/09/05 09:48:21 by ljiriste #+# #+# */
+/* Updated: 2023/09/05 11:47:52 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft.h"
+
+int ft_abs(int n)
+{
+ if (n < 0)
+ return (-n);
+ else
+ return (n);
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_ctoa.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/09/05 09:55:17 by ljiriste #+# #+# */
+/* Updated: 2023/09/05 09:56:02 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <stdlib.h> //malloc
+#include "libft.h"
+
+char *ft_ctoa(char c)
+{
+ char *res;
+
+ res = malloc(2 * sizeof(char));
+ if (res == NULL)
+ return (res);
+ res[0] = c;
+ res[1] = '\0';
+ return (res);
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_itoa_base.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/09/05 09:46:11 by ljiriste #+# #+# */
+/* Updated: 2023/09/05 11:46:44 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <stdlib.h> //malloc
+#include <stdint.h> //intmax_t
+#include "libft.h"
+
+static intmax_t abs_max(intmax_t n)
+{
+ if (n < 0)
+ return (-n);
+ else
+ return (n);
+}
+
+static int size_needed(intmax_t n, size_t base_len)
+{
+ int res;
+
+ if (n == 0)
+ return (2);
+ res = 1;
+ if (n < 0)
+ ++res;
+ while (n != 0)
+ {
+ ++res;
+ n /= base_len;
+ }
+ return (res);
+}
+
+static int valid_base(const char *base)
+{
+ int i;
+ int j;
+
+ if (ft_strlen(base) < 2)
+ return (0);
+ i = 0;
+ while (base[i])
+ {
+ j = i + 1;
+ while (base[j])
+ if (base[i] == base[j++])
+ return (0);
+ ++i;
+ }
+ return (1);
+}
+
+char *ft_itoa_base(intmax_t n, const char *base)
+{
+ int size;
+ int base_len;
+ char *res;
+
+ if (!valid_base(base))
+ return (NULL);
+ base_len = ft_strlen(base);
+ size = size_needed(n, base_len);
+ res = malloc(size);
+ if (res == NULL)
+ return (res);
+ if (n < 0)
+ res[0] = '-';
+ res[size--] = '\0';
+ while (n != 0)
+ {
+ res[size--] = base[abs_max(n % base_len)];
+ n /= base_len;
+ }
+ return (res);
+}
/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/08/15 12:58:15 by ljiriste #+# #+# */
-/* Updated: 2023/08/24 09:24:32 by ljiriste ### ########.fr */
+/* Updated: 2023/09/05 11:47:43 by ljiriste ### ########.fr */
/* */
/* ************************************************************************** */
# define LIBFT_H
# include <sys/types.h>
+# include <stdint.h>
int ft_isalnum(int c);
int ft_isalpha(int c);
int ft_isupper(int c);
int ft_isascii(int c);
+int ft_abs(int n);
+
void *ft_memset(void *s, int c, size_t n);
void *ft_memcpy(void *dest, const void *src, size_t n);
void *ft_memmove(void *dest, const void *src, size_t n);
char **ft_split(const char *s, char c);
char *ft_itoa(int n);
+char *ft_itoa_base(intmax_t n, const char *base);
char *ft_strmapi(const char *s, char (*f)(unsigned int, char));
void ft_striteri(char *s, void (*f)(unsigned int, char *));