This commit is contained in:
pbonilla 2024-02-14 09:58:04 +01:00
commit 8d69e7d1df
70 changed files with 2575 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
*.o
*.a
woody_woodpacker

37
Makefile Normal file
View File

@ -0,0 +1,37 @@
NAME = woody_woodpacker
SRCS_PATH = srcs/
SRCS = $(SRCS_PATH)main.c
OBJS = ${SRCS:.c=.o}
CC = gcc
RM = rm -f
LIBFT_FLAGS = ft_printf/libftprintf.a
CFLAGS = -Wall -Wextra -Werror
all: ${NAME}
.c.o:
${CC} ${DEFINES} ${CFLAGS} -c $< -o $@
$(NAME): ${OBJS}
make -C ft_printf
${CC} ${OBJS} ${LIBFT_FLAGS} -o ${NAME}
clean:
make -C ft_printf clean
${RM} ${OBJS}
fclean:
make -C ft_printf fclean
${RM} ${NAME}
re: fclean
make all
.PHONY : all clean fclean re

63
ft_printf/Makefile Normal file
View File

@ -0,0 +1,63 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: pbonilla <eirodeis.lepnj@gmail.com> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2021/01/18 18:08:51 by pbonilla #+# #+# #
# Updated: 2021/03/12 12:27:09 by pbonilla ### ########.fr #
# #
# **************************************************************************** #
LIBFT = ./libft/libft.a
NAME = libftprintf.a
SRCS_PATH = srcs/
SRCS = $(SRCS_PATH)ft_printf.c \
$(SRCS_PATH)ft_parser.c \
$(SRCS_PATH)ft_int_case.c \
$(SRCS_PATH)ft_char_case.c \
$(SRCS_PATH)ft_str_case.c \
$(SRCS_PATH)ft_ui_case.c \
$(SRCS_PATH)ft_x_case.c \
$(SRCS_PATH)ft_ptr_case.c \
$(SRCS_PATH)ft_percent_case.c \
$(SRCS_PATH)ft_printf_memset.c \
OBJS = ${SRCS:.c=.o}
CC = gcc
RM = rm -f
CFLAGS = -Wall -Wextra -Werror
INCLUDES = -I libft
all: ${NAME}
.c.o:
${CC} ${INCLUDES} ${DEFINES} ${CFLAGS} -c $< -o $@
$(NAME): ${OBJS}
$(MAKE) bonus -C ./libft
cp libft/libft.a $(NAME)
ar -rcs $(NAME) $(OBJS)
ranlib $(NAME)
clean:
$(MAKE) clean -C ./libft
${RM} ${OBJS}
fclean: clean
$(MAKE) fclean -C ./libft
${RM} ${NAME}
re: fclean all
.PHONY : all clean fclean re

View File

@ -0,0 +1,41 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pbonilla <eirodeis.lepnj@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/02/11 15:21:19 by pbonilla #+# #+# */
/* Updated: 2021/03/21 20:11:37 by pbonilla ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FT_PRINTF_H
# define FT_PRINTF_H
# include "../libft/libft.h"
# include <stdarg.h>
# include <stdio.h>
typedef struct s_param
{
int minus;
int zero;
int width;
int prec;
int type;
int len;
} t_param;
t_param ft_init_param(void);
void *ft_printf_memset(void *s, size_t n, t_param *param);
int ft_printf(const char *s, ...);
int ft_parse_param(const char *s, int i, t_param *par,
va_list args);
char *ft_int_case(t_param *param, int i);
char *ft_char_case(t_param *param, int i);
char *ft_ui_case(t_param *param, unsigned int i);
char *ft_x_case(t_param *param, unsigned long i);
char *ft_ptr_case(t_param *param, unsigned long long i);
char *ft_str_case(t_param *param, char *str);
char *ft_percent_case(t_param *param);
#endif

102
ft_printf/libft/Makefile Normal file
View File

@ -0,0 +1,102 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: pbonilla <eirodeis.lepnj@gmail.com> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2021/01/18 18:08:51 by pbonilla #+# #+# #
# Updated: 2021/02/07 14:20:29 by pbonilla ### ########.fr #
# #
# **************************************************************************** #
NAME = libft.a
SRCS_PATH = ./
SRCS = $(SRCS_PATH)ft_atoi.c \
$(SRCS_PATH)ft_toupper.c \
$(SRCS_PATH)ft_bzero.c \
$(SRCS_PATH)ft_isalnum.c \
$(SRCS_PATH)ft_tolower.c \
$(SRCS_PATH)ft_memcpy.c \
$(SRCS_PATH)ft_memccpy.c \
$(SRCS_PATH)ft_memmove.c \
$(SRCS_PATH)ft_memset.c \
$(SRCS_PATH)ft_memchr.c \
$(SRCS_PATH)ft_memcmp.c \
$(SRCS_PATH)ft_strlcat.c \
$(SRCS_PATH)ft_strnstr.c \
$(SRCS_PATH)ft_strlcat.c \
$(SRCS_PATH)ft_strlen.c \
$(SRCS_PATH)ft_strchr.c \
$(SRCS_PATH)ft_strrchr.c \
$(SRCS_PATH)ft_isalpha.c \
$(SRCS_PATH)ft_isascii.c \
$(SRCS_PATH)ft_strlcpy.c \
$(SRCS_PATH)ft_strncmp.c \
$(SRCS_PATH)ft_isdigit.c \
$(SRCS_PATH)ft_isprint.c \
$(SRCS_PATH)ft_toupper.c \
$(SRCS_PATH)ft_bzero.c \
$(SRCS_PATH)ft_strdup.c \
$(SRCS_PATH)ft_strnstr.c \
$(SRCS_PATH)ft_calloc.c \
$(SRCS_PATH)ft_substr.c \
$(SRCS_PATH)ft_strjoin.c \
$(SRCS_PATH)ft_u_itoa.c \
$(SRCS_PATH)ft_itoa.c \
$(SRCS_PATH)ft_strmapi.c \
$(SRCS_PATH)ft_putchar_fd.c \
$(SRCS_PATH)ft_putstr_fd.c \
$(SRCS_PATH)ft_putnbr_fd.c \
$(SRCS_PATH)ft_putendl_fd.c \
$(SRCS_PATH)ft_strtrim.c \
$(SRCS_PATH)ft_split.c \
$(SRCS_PATH)ft_u_convert.c \
$(SRCS_PATH)ft_convert_base.c \
$(SRCS_PATH)ft_revert_int.c \
BONUS = $(SRCS_PATH)ft_lstnew.c \
$(SRCS_PATH)ft_lstadd_front.c \
$(SRCS_PATH)ft_lstsize.c \
$(SRCS_PATH)ft_lstlast.c \
$(SRCS_PATH)ft_lstadd_back.c \
$(SRCS_PATH)ft_lstdelone.c \
$(SRCS_PATH)ft_lstclear.c \
$(SRCS_PATH)ft_lstiter.c \
$(SRCS_PATH)ft_lstmap.c \
OBJS = ${SRCS:.c=.o}
BONUS_OBJS = $(BONUS:.c=.o)
CC = gcc
RM = rm -f
CFLAGS = -Wall -Wextra -Werror
$(NAME): $(OBJS)
ar rc $(NAME) $(OBJS)
ranlib $(NAME)
all: $(NAME)
.c.o:
${CC} ${INCLUDES} ${DEFINES} ${CFLAGS} -c $< -o $@
clean:
rm -rf $(OBJS) $(BONUS_OBJS)
fclean: clean
rm -rf $(NAME)
re: fclean all
bonus: $(OBJS) $(BONUS_OBJS)
ar rc $(NAME) $(OBJS) $(BONUS_OBJS)
ranlib $(NAME)
.PHONY : all clean fclean re bonus

35
ft_printf/libft/ft_atoi.c Normal file
View File

@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pbonilla <eirodeis.lepnj@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/11 16:00:14 by pbonilla #+# #+# */
/* Updated: 2020/11/18 14:03:00 by pbonilla ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_atoi(const char *nptr)
{
int nbr;
int sgn;
sgn = 1;
nbr = 0;
while (*nptr && (*nptr == ' ' || *nptr == '\n' || *nptr == '\t' ||
*nptr == '\v' || *nptr == '\f' || *nptr == '\r'))
++nptr;
if (*nptr == '-')
sgn *= -1;
if (*nptr == '-' || *nptr == '+')
++nptr;
while (*nptr && *nptr >= '0' && *nptr <= '9')
{
nbr = nbr * 10 + (*nptr - 48);
++nptr;
}
return (nbr * sgn);
}

View File

@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_bzero.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pbonilla <eirodeis.lepnj@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/10/27 18:43:42 by pbonilla #+# #+# */
/* Updated: 2020/11/11 15:25:20 by pbonilla ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_bzero(void *s, size_t n)
{
unsigned char *buff;
unsigned int i;
buff = s;
i = -1;
while (++i != n)
*(buff + i) = 0;
}

View File

@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_calloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pbonilla <eirodeis.lepnj@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/11 18:51:50 by pbonilla #+# #+# */
/* Updated: 2020/11/11 19:19:16 by pbonilla ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_calloc(size_t nmemb, size_t size)
{
char *s;
if (!(s = malloc(size * nmemb)))
return (NULL);
ft_memset(s, 0, size * nmemb);
return (s);
}

View File

@ -0,0 +1,118 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_convert_base.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pbonilla <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/09/22 19:22:14 by pbonilla #+# #+# */
/* Updated: 2021/03/19 18:42:40 by pbonilla ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <stdio.h>
int isinbase(char c, char *base)
{
int i;
i = 0;
while (base[i])
{
if (base[i] == c)
return (i);
++i;
}
return (-1);
}
long ft_atoi_base(char *str, char *base)
{
int len_base;
int i;
int signe;
long long nbr;
signe = 1;
i = 0;
nbr = 0;
len_base = ft_strlen(base);
while (str[i] == '-' || str[i] == '+')
{
if (str[i] == '-')
signe *= -1;
i++;
}
while (isinbase(str[i], base) >= 0)
{
nbr = (len_base * nbr) + isinbase(str[i], base);
i++;
}
return (signe * nbr);
}
int get_size_in_char(long long nbr, int len_base)
{
int i;
i = 1;
if (nbr < 0)
++i;
while (nbr / len_base)
{
nbr = nbr / len_base;
++i;
}
return (i);
}
char *write_base(char *str, long long nbr, char *base, int *i_sgn)
{
int len_base;
long long nb;
len_base = ft_strlen(base);
nb = nbr;
if (nb < 0)
nb *= -1;
if (nb >= len_base)
{
str[i_sgn[0]] = base[nb % len_base];
i_sgn[0] += 1;
write_base(str, nb / len_base, base, i_sgn);
}
else
{
str[i_sgn[0]] = base[nb];
if (i_sgn[1])
str[i_sgn[0] + 1] = '-';
str[i_sgn[0] + 1 + i_sgn[1]] = 0;
}
return (str);
}
char *ft_convert_base(char *nbr, char *base_from, char *base_to)
{
char *str;
int len_base;
int size_char;
long long number;
int i_sgn[2];
i_sgn[0] = 0;
i_sgn[1] = 0;
if (!nbr || !base_from || !base_to)
return (NULL);
number = ft_atoi_base(nbr, base_from);
len_base = ft_strlen(base_to);
size_char = get_size_in_char(number, len_base);
if (!(str = malloc(sizeof(char) * (size_char + 1))))
return (ft_strdup(""));
if (number < 0)
i_sgn[1] = 1;
str = write_base(str, number, base_to, i_sgn);
str[size_char] = 0;
ft_rev_int_tab(str, size_char);
return (str);
}

View File

@ -0,0 +1,17 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isalnum.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pbonilla <eirodeis.lepnj@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/10/25 17:21:39 by pbonilla #+# #+# */
/* Updated: 2021/01/19 16:24:38 by pbonilla ### ########.fr */
/* */
/* ************************************************************************** */
int ft_isalnum(int c)
{
return ((c >= '0' && c <= '9') ||
(c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'));
}

View File

@ -0,0 +1,16 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isalpha.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pbonilla <eirodeis.lepnj@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/10/25 16:41:59 by pbonilla #+# #+# */
/* Updated: 2021/01/19 16:26:50 by pbonilla ### ########.fr */
/* */
/* ************************************************************************** */
int ft_isalpha(int c)
{
return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'));
}

View File

@ -0,0 +1,16 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isascii.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pbonilla <eirodeis.lepnj@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/10/25 17:35:50 by pbonilla #+# #+# */
/* Updated: 2021/01/28 13:41:22 by pbonilla ### ########.fr */
/* */
/* ************************************************************************** */
int ft_isascii(int c)
{
return (c >= 0 && c <= 127);
}

View File

@ -0,0 +1,16 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isdigit.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pbonilla <eirodeis.lepnj@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/10/25 16:43:33 by pbonilla #+# #+# */
/* Updated: 2021/01/19 16:27:51 by pbonilla ### ########.fr */
/* */
/* ************************************************************************** */
int ft_isdigit(int c)
{
return (c >= '0' && c <= '9');
}

View File

@ -0,0 +1,16 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isprint.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pbonilla <eirodeis.lepnj@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/10/25 17:38:36 by pbonilla #+# #+# */
/* Updated: 2020/11/18 14:08:51 by pbonilla ### ########.fr */
/* */
/* ************************************************************************** */
int ft_isprint(int c)
{
return (c >= 32 && c <= 126);
}

58
ft_printf/libft/ft_itoa.c Normal file
View File

@ -0,0 +1,58 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_itoa.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pbonilla <eirodeis.lepnj@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/24 21:27:16 by pbonilla #+# #+# */
/* Updated: 2021/01/31 04:53:05 by pbonilla ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int number_len(int n)
{
int size;
if (n == 0)
return (1);
size = 0;
if (n < 0)
{
n = -n;
++size;
}
while (n != 0)
{
n /= 10;
++size;
}
return (size);
}
char *ft_itoa(int n)
{
long long_n;
char *number;
int size;
long_n = n;
size = number_len(n);
if (!(number = malloc(sizeof(char) * (size + 1))))
return (NULL);
number[size] = 0;
--size;
if (long_n < 0)
long_n = -long_n;
while (size >= 0)
{
number[size] = '0' + (long_n % 10);
--size;
long_n /= 10;
}
if (n < 0)
number[0] = '-';
return (number);
}

View File

@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstadd_back_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pbonilla <eirodeis.lepnj@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/12/04 16:04:08 by pbonilla #+# #+# */
/* Updated: 2020/12/04 16:04:11 by pbonilla ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstadd_back(t_list **alst, t_list *new)
{
t_list *suiv;
if (!*alst)
{
*alst = new;
return ;
}
suiv = ft_lstlast(*alst);
suiv->next = new;
}

View File

@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstadd_front_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pbonilla <eirodeis.lepnj@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/12/04 16:04:57 by pbonilla #+# #+# */
/* Updated: 2020/12/04 16:04:59 by pbonilla ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstadd_front(t_list **alst, t_list *new)
{
if (alst && new)
{
new->next = *alst;
*alst = new;
}
}

View File

@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstclear_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pbonilla <eirodeis.lepnj@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/12/04 16:05:21 by pbonilla #+# #+# */
/* Updated: 2020/12/04 16:05:21 by pbonilla ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstclear(t_list **lst, void (*del)(void*))
{
t_list *tmp;
if (!lst)
return ;
while (*lst)
{
tmp = (*lst)->next;
ft_lstdelone(*lst, del);
(*lst) = tmp;
}
*lst = NULL;
}

View File

@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstdelone_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pbonilla <eirodeis.lepnj@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/12/04 16:05:34 by pbonilla #+# #+# */
/* Updated: 2020/12/04 16:05:37 by pbonilla ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstdelone(t_list *lst, void (*del)(void *))
{
if (!lst)
return ;
if (del)
{
free(lst);
del(lst->content);
}
}

View File

@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstiter_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pbonilla <eirodeis.lepnj@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/12/04 16:05:51 by pbonilla #+# #+# */
/* Updated: 2020/12/04 16:05:52 by pbonilla ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstiter(t_list *lst, void (*f)(void *))
{
t_list *tmp;
tmp = lst;
if (!f)
return ;
while (tmp)
{
f(tmp->content);
tmp = tmp->next;
}
}

View File

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstlast_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pbonilla <eirodeis.lepnj@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/12/04 16:06:04 by pbonilla #+# #+# */
/* Updated: 2020/12/04 16:06:04 by pbonilla ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *ft_lstlast(t_list *lst)
{
t_list *suiv;
if (!lst)
return (NULL);
suiv = lst;
while (suiv->next)
suiv = suiv->next;
return (suiv);
}

View File

@ -0,0 +1,34 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstmap_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pbonilla <eirodeis.lepnj@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/12/04 16:06:16 by pbonilla #+# #+# */
/* Updated: 2021/02/01 08:27:04 by pbonilla ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *ft_lstmap(t_list *l, void *(*f)(void *), void (*del)(void *))
{
t_list *new_lst;
t_list *new_elem;
if (!f)
return (NULL);
new_lst = NULL;
while (l)
{
if (!(new_elem = ft_lstnew(f(l->content))))
{
ft_lstclear(&new_lst, del);
return (NULL);
}
ft_lstadd_back(&new_lst, new_elem);
l = l->next;
}
return (new_lst);
}

View File

@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstnew_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pbonilla <eirodeis.lepnj@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/12/04 16:06:31 by pbonilla #+# #+# */
/* Updated: 2020/12/04 16:06:31 by pbonilla ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *ft_lstnew(void *content)
{
t_list *new;
if (!(new = malloc(sizeof(t_list))))
return (NULL);
new->content = content;
new->next = NULL;
return (new);
}

View File

@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstsize_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pbonilla <eirodeis.lepnj@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/12/04 16:06:42 by pbonilla #+# #+# */
/* Updated: 2020/12/04 16:06:43 by pbonilla ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_lstsize(t_list *lst)
{
int i;
t_list *suiv;
i = 1;
suiv = lst;
if (!lst)
return (0);
while (suiv->next)
{
suiv = suiv->next;
++i;
}
return (i);
}

View File

@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memccpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pbonilla <eirodeis.lepnj@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/10/27 19:40:08 by pbonilla #+# #+# */
/* Updated: 2021/01/29 12:00:11 by pbonilla ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memccpy(void *dest, const void *src, int c, size_t n)
{
unsigned char *buff;
unsigned char *buff2;
unsigned int i;
buff = (unsigned char *)dest;
buff2 = (unsigned char *)src;
i = 0;
while (i < n)
{
buff[i] = buff2[i];
if (buff2[i] == (unsigned char)c)
return ((void *)(dest + i + 1));
++i;
}
return (NULL);
}

View File

@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pbonilla <eirodeis.lepnj@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/10/29 12:11:59 by pbonilla #+# #+# */
/* Updated: 2020/11/20 23:33:24 by pbonilla ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memchr(const void *s, int c, size_t n)
{
unsigned char *buff;
unsigned int i;
buff = (unsigned char *)s;
i = 0;
while (i != n)
{
if (buff[i] == (unsigned char)c)
return ((void *)&buff[i]);
++i;
}
return (NULL);
}

View File

@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pbonilla <eirodeis.lepnj@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/10/29 12:23:50 by pbonilla #+# #+# */
/* Updated: 2021/01/29 13:09:55 by pbonilla ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_memcmp(const void *s1, const void *s2, size_t n)
{
unsigned char *ss1;
unsigned char *ss2;
unsigned int i;
ss1 = (unsigned char *)s1;
ss2 = (unsigned char *)s2;
i = -1;
if (n == 0)
return (0);
while (++i < n)
{
if (ss1[i] != ss2[i])
return (ss1[i] - ss2[i]);
}
return (0);
}

View File

@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pbonilla <eirodeis.lepnj@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/10/27 18:52:38 by pbonilla #+# #+# */
/* Updated: 2021/01/29 12:11:19 by pbonilla ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memcpy(void *dest, const void *src, size_t n)
{
unsigned char *buff;
unsigned char *buff2;
unsigned int i;
buff = (unsigned char *)dest;
buff2 = (unsigned char *)src;
if (!buff && !buff2)
return (NULL);
i = -1;
while (++i != n)
buff[i] = buff2[i];
return (buff);
}

View File

@ -0,0 +1,39 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memmove.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pbonilla <eirodeis.lepnj@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/10/27 22:19:34 by pbonilla #+# #+# */
/* Updated: 2021/01/29 13:08:14 by pbonilla ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memmove(void *dest, const void *src, size_t n)
{
unsigned char *dest2;
unsigned char *src2;
unsigned int i;
dest2 = (unsigned char *)dest;
src2 = (unsigned char *)src;
i = -1;
if (!dest2 && !src2)
return (dest2);
if (src >= dest)
{
while (++i != n)
*(dest2 + i) = *(src2 + i);
}
else
{
src2 += n;
dest2 += n;
while (n--)
*--dest2 = *--src2;
}
return (dest2);
}

View File

@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memset.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pbonilla <eirodeis.lepnj@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/10/27 17:57:35 by pbonilla #+# #+# */
/* Updated: 2020/11/11 15:46:56 by pbonilla ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memset(void *s, int c, size_t n)
{
unsigned char *buff;
unsigned int i;
buff = s;
i = -1;
while (++i != n)
*(buff + i) = c;
s = (void *)buff;
return (s);
}

View File

@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putchar_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pbonilla <eirodeis.lepnj@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/25 18:28:15 by pbonilla #+# #+# */
/* Updated: 2020/12/03 17:41:45 by pbonilla ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putchar_fd(char c, int fd)
{
write(fd, &c, 1);
}

View File

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putendl_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pbonilla <eirodeis.lepnj@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/12/01 18:27:47 by pbonilla #+# #+# */
/* Updated: 2020/12/03 17:45:49 by pbonilla ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putendl_fd(char *s, int fd)
{
if (s)
write(fd, s, ft_strlen(s));
write(fd, "\n", 1);
}

View File

@ -0,0 +1,70 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr_base.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pbonilla <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/09/16 14:58:50 by pbonilla #+# #+# */
/* Updated: 2021/02/28 02:52:20 by pbonilla ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void write_base(long nbr, char *base)
{
long tmp;
int len_base;
tmp = nbr;
len_base = ft_strlen(base);
if (tmp < 0)
{
ft_putchar('-');
tmp *= -1;
}
if (tmp > len_base - 1)
{
write_base(tmp / len_base, base);
write_base(tmp % len_base, base);
}
else
ft_putchar(tmp + base[0]);
}
int check_base(char *base, int len_base)
{
int i;
int j;
i = 0;
if (len_base > 1)
{
while (base[i])
{
j = i;
while (base[j])
{
if ((base[i] == base[j] && i != j) ||
base[j] == '+' || base[j] == '-')
return (0);
j++;
}
i++;
}
return (1);
}
return (0);
}
void ft_putnbr_base(int nbr, char *base)
{
long tmp;
int len_base;
tmp = nbr;
len_base = ft_strlen(base);
if (check_base(base, len_base))
write_base(tmp, base);
}

View File

@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pbonilla <eirodeis.lepnj@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/12/01 17:58:34 by pbonilla #+# #+# */
/* Updated: 2020/12/01 18:25:48 by pbonilla ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putnbr_fd(int n, int fd)
{
long nb;
nb = n;
if (nb < 0)
{
ft_putchar_fd('-', fd);
nb = -nb;
}
if (nb >= 10)
{
ft_putnbr_fd(nb / 10, fd);
ft_putnbr_fd(nb % 10, fd);
}
else
ft_putchar_fd(nb + '0', fd);
}

View File

@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putstr_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pbonilla <eirodeis.lepnj@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/12/01 17:49:54 by pbonilla #+# #+# */
/* Updated: 2020/12/03 17:43:48 by pbonilla ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putstr_fd(char *s, int fd)
{
if (s)
write(fd, s, ft_strlen(s));
}

View File

@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_revert_int.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pbonilla <eirodeis.lepnj@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/02/28 03:57:26 by pbonilla #+# #+# */
/* Updated: 2021/03/19 18:44:09 by pbonilla ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_rev_int_tab(char *tab, int size)
{
char tmp;
int i;
i = size;
while (i > size / 2)
{
tmp = tab[i - 1];
tab[i - 1] = tab[size - i];
tab[size - i] = tmp;
i--;
}
}

View File

@ -0,0 +1,96 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_split.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pbonilla <eirodeis.lepnj@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/02/01 08:32:47 by pbonilla #+# #+# */
/* Updated: 2021/02/07 14:09:27 by pbonilla ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int count_word(char const *s, char c)
{
int i;
int nb_word;
i = -1;
nb_word = 0;
while (s[++i])
{
if (s[i] == c && i != 0 && s[i - 1] != c)
++nb_word;
}
if (i == 0 || s[i - 1] != c)
++nb_word;
return (nb_word);
}
int count_char(char const *s, char c, int i)
{
int size;
size = 0;
while (s[i] && s[i] != c)
{
++size;
++i;
}
return (size);
}
char **free_all(char **splitey, int n)
{
while (n > 0)
{
--n;
free(splitey[n]);
}
free(splitey);
return (NULL);
}
char **fill_splitey(char const *s, char **splitey, char c, int nb)
{
int i;
int j;
int k;
i = 0;
j = 0;
while (s[i] && j < nb)
{
k = 0;
while (s[i] == c)
++i;
if (!(splitey[j] = malloc(sizeof(char) * (count_char(s, c, i) + 1))))
return (free_all(splitey, j));
while (s[i] && s[i] != c)
splitey[j][k++] = s[i++];
splitey[j][k] = 0;
++j;
}
splitey[j] = 0;
return (splitey);
}
char **ft_split(char const *s, char c)
{
char **splitey;
int nb_words;
if (!s)
return (NULL);
nb_words = count_word(s, c);
if (!(splitey = malloc(sizeof(char *) * (nb_words + 1))))
return (NULL);
if (!nb_words)
{
splitey[0] = 0;
return (splitey);
}
return (fill_splitey(s, splitey, c, nb_words));
}

View File

@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pbonilla <eirodeis.lepnj@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/10/29 12:37:26 by pbonilla #+# #+# */
/* Updated: 2020/12/04 15:40:05 by pbonilla ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strchr(const char *s, int c)
{
int i;
char *buff;
buff = (char *)s;
i = -1;
while (buff[++i])
{
if (buff[i] == (char)c)
return ((char *)&buff[i]);
}
if (buff[i] == (char)c)
return ((char *)&buff[i]);
return (NULL);
}

View File

@ -0,0 +1,19 @@
#include "libft.h"
int ft_strcmp(const char *s1, const char *s2)
{
unsigned char *ss1;
unsigned char *ss2;
size_t i;
ss1 = (unsigned char *)s1;
ss2 = (unsigned char *)s2;
i = 0;
while (ss1[i] || ss2[i])
{
if (ss1[i] != ss2[i])
return (ss1[i] - ss2[i]);
++i;
}
return (0);
}

View File

@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pbonilla <eirodeis.lepnj@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/11 18:45:41 by pbonilla #+# #+# */
/* Updated: 2021/01/31 04:55:04 by pbonilla ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strdup(const char *s)
{
char *dup;
int i;
if (!(dup = malloc(sizeof(char) * ft_strlen(s) + 1)))
return (NULL);
i = -1;
while (s[++i])
dup[i] = s[i];
dup[i] = 0;
return (dup);
}

View File

@ -0,0 +1,39 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pbonilla <eirodeis.lepnj@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/24 15:20:38 by pbonilla #+# #+# */
/* Updated: 2020/11/24 15:52:53 by pbonilla ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strjoin(char const *s1, char const *s2)
{
char *new;
size_t len_s1;
size_t len_s2;
size_t i;
if (!(s1 && s2))
return (NULL);
len_s1 = ft_strlen(s1);
len_s2 = ft_strlen(s2);
if (!(new = malloc(sizeof(char *) * (len_s1 + len_s2 + 1))))
return (NULL);
i = -1;
while (s1[++i])
new[i] = s1[i];
i = -1;
while (s2[++i])
{
new[len_s1] = s2[i];
len_s1++;
}
new[len_s1] = 0;
return (new);
}

View File

@ -0,0 +1,39 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pbonilla <eirodeis.lepnj@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/09 19:11:10 by pbonilla #+# #+# */
/* Updated: 2020/12/03 17:41:01 by pbonilla ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
size_t ft_strlcat(char *dst, const char *src, size_t size)
{
size_t dst_size;
size_t src_size;
size_t i;
i = 0;
src_size = 0;
dst_size = 0;
while (src[src_size])
src_size++;
if (size == 0)
return (src_size);
while (dst_size < size && dst[dst_size])
dst_size++;
if (size <= dst_size)
return (size + src_size);
while (size && (--size - dst_size) && src[i])
{
dst[dst_size + i] = src[i];
i++;
}
dst[dst_size + i] = 0;
return (src_size + dst_size);
}

View File

@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pbonilla <eirodeis.lepnj@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/08 17:09:59 by pbonilla #+# #+# */
/* Updated: 2020/11/11 21:38:14 by pbonilla ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
size_t ft_strlcpy(char *dst, const char *src, size_t size)
{
size_t i;
size_t j;
if (!dst)
return (0);
i = ft_strlen(src);
if (size == 0)
return (i);
j = 0;
while (j < i && j < size - 1)
{
dst[j] = src[j];
++j;
}
dst[j] = 0;
return (i);
}

View File

@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlen.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pbonilla <eirodeis.lepnj@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/10/29 12:32:56 by pbonilla #+# #+# */
/* Updated: 2021/02/18 16:27:54 by pbonilla ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
size_t ft_strlen(const char *s)
{
char *buff;
size_t i;
buff = (char *)s;
if (!buff)
return (0);
i = -1;
while (buff[++i])
;
return (i);
}

View File

@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmapi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pbonilla <eirodeis.lepnj@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/25 17:46:08 by pbonilla #+# #+# */
/* Updated: 2021/01/31 04:53:57 by pbonilla ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
{
char *sf;
size_t i;
if (!s || !f)
return (NULL);
if (!(sf = malloc(sizeof(char) * (ft_strlen(s) + 1))))
return (NULL);
i = -1;
while (s[++i])
sf[i] = (*f)(i, s[i]);
sf[i] = 0;
return (sf);
}

View File

@ -0,0 +1,48 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pbonilla <eirodeis.lepnj@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/04 16:48:09 by pbonilla #+# #+# */
/* Updated: 2021/02/04 02:28:25 by pbonilla ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_strcmp(const char *s1, const char *s2)
{
unsigned char *ss1;
unsigned char *ss2;
size_t i;
ss1 = (unsigned char *)s1;
ss2 = (unsigned char *)s2;
i = 0;
while (ss1[i] || ss2[i])
{
if (ss1[i] != ss2[i])
return (ss1[i] - ss2[i]);
++i;
}
return (0);
}
int ft_strncmp(const char *s1, const char *s2, size_t n)
{
unsigned char *ss1;
unsigned char *ss2;
size_t i;
ss1 = (unsigned char *)s1;
ss2 = (unsigned char *)s2;
i = -1;
while (++i < n && (ss1[i] || ss2[i]))
{
if (ss1[i] != ss2[i])
return (ss1[i] - ss2[i]);
}
return (0);
}

View File

@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pbonilla <eirodeis.lepnj@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/09 19:15:12 by pbonilla #+# #+# */
/* Updated: 2021/01/30 18:31:22 by pbonilla ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strnstr(const char *big, const char *little, size_t len)
{
size_t len_l;
if (*little == 0)
return ((char *)big);
len_l = ft_strlen(little);
while (*big != 0 && len-- >= len_l)
{
if (*big == *little && ft_strncmp(big, little, len_l) == 0)
return ((char *)big);
big++;
}
return (NULL);
}

View File

@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strrchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pbonilla <eirodeis.lepnj@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/10/29 13:10:04 by pbonilla #+# #+# */
/* Updated: 2020/11/19 15:09:23 by pbonilla ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strrchr(const char *s, int c)
{
int i;
int j;
i = -1;
j = -1;
while (s[++i])
{
if (s[i] == (char)c)
j = i;
}
if (s[i] == (char)c)
return ((char *)&s[i]);
if (j == -1)
return (NULL);
return ((char *)&s[j]);
}

View File

@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pbonilla <eirodeis.lepnj@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/26 15:19:18 by pbonilla #+# #+# */
/* Updated: 2021/02/04 02:37:12 by pbonilla ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strtrim(char const *s1, char const *set)
{
size_t size_s1;
if (!s1 || !set)
return (NULL);
while (*s1 && ft_strchr(set, *s1))
++s1;
size_s1 = ft_strlen(s1);
while (size_s1 && ft_strchr(set, s1[size_s1]))
--size_s1;
return (ft_substr(s1, 0, size_s1 + 1));
}

View File

@ -0,0 +1,38 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_substr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pbonilla <eirodeis.lepnj@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/12 16:24:37 by pbonilla #+# #+# */
/* Updated: 2021/01/31 05:13:41 by pbonilla ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_substr(char const *s, unsigned int start, size_t len)
{
char *sub;
size_t i;
size_t j;
if (!s)
return (NULL);
if (!(sub = malloc(sizeof(char) * (len + 1))))
return (NULL);
i = 0;
j = 0;
while (s[i])
{
if (i >= start && j < len)
{
sub[j] = s[i];
++j;
}
i++;
}
sub[j] = 0;
return (sub);
}

View File

@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_tolower.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pbonilla <eirodeis.lepnj@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/10/25 17:10:14 by pbonilla #+# #+# */
/* Updated: 2020/10/25 17:16:22 by pbonilla ### ########.fr */
/* */
/* ************************************************************************** */
int ft_tolower(int c)
{
if (c >= 'A' && c <= 'Z')
return (c + 32);
return (c);
}

View File

@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_toupper.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pbonilla <eirodeis.lepnj@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/10/25 17:04:47 by pbonilla #+# #+# */
/* Updated: 2020/10/25 17:09:00 by pbonilla ### ########.fr */
/* */
/* ************************************************************************** */
int ft_toupper(int c)
{
if (c >= 'a' && c <= 'z')
return (c - 32);
return (c);
}

View File

@ -0,0 +1,113 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_u_convert.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pbonilla <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/09/22 19:22:14 by pbonilla #+# #+# */
/* Updated: 2021/03/19 19:07:30 by pbonilla ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <stdio.h>
int u_isinbase(char c, char *base)
{
int i;
i = 0;
while (base[i])
{
if (base[i] == c)
return (i);
++i;
}
return (-1);
}
long u_ft_atoi_base(char *str, char *base)
{
int len_base;
int i;
int signe;
unsigned long long nbr;
signe = 1;
i = 0;
nbr = 0;
len_base = ft_strlen(base);
while (str[i] == '-' || str[i] == '+')
{
if (str[i] == '-')
signe *= -1;
i++;
}
while (u_isinbase(str[i], base) >= 0)
{
nbr = (len_base * nbr) + u_isinbase(str[i], base);
i++;
}
return (signe * nbr);
}
int u_get_size_in_char(unsigned long long nbr, int len_base)
{
int i;
i = 1;
while (nbr / len_base)
{
nbr = nbr / len_base;
++i;
}
return (i);
}
char *u_write_base(char *s, unsigned long long n,
char *b, int *i)
{
unsigned long long len_base;
unsigned long long nb;
len_base = ft_strlen(b);
nb = n;
if (nb >= len_base)
{
s[i[0]] = b[nb % len_base];
i[0] += 1;
u_write_base(s, nb / len_base, b, i);
}
else
{
s[i[0]] = b[nb];
if (i[1])
s[i[0] + 1] = '-';
s[i[0] + 1 + i[1]] = 0;
}
return (s);
}
char *ft_u_convert(char *nbr, char *b_f, char *b_t)
{
char *str;
int len_base;
int size_char;
unsigned long long number;
int i_sgn[2];
i_sgn[0] = 0;
i_sgn[1] = 0;
if (!nbr || !b_f || !b_t)
return (NULL);
number = u_ft_atoi_base(nbr, b_f);
len_base = ft_strlen(b_t);
size_char = u_get_size_in_char(number, len_base);
if (!(str = malloc(sizeof(char) * (size_char + 1))))
return (ft_strdup(""));
str = u_write_base(str, number, b_t, i_sgn);
str[size_char] = 0;
ft_rev_int_tab(str, size_char);
return (str);
}

View File

@ -0,0 +1,51 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_u_itoa.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pbonilla <eirodeis.lepnj@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/24 21:27:16 by pbonilla #+# #+# */
/* Updated: 2021/03/19 18:16:49 by pbonilla ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int number_u_len(unsigned long long n)
{
int size;
if (n == 0)
return (1);
size = 0;
n = -n;
++size;
while (n != 0)
{
n /= 10;
++size;
}
return (size);
}
char *ft_u_itoa(unsigned long long n)
{
unsigned long long long_n;
char *number;
int size;
long_n = n;
size = number_u_len(n);
if (!(number = malloc(sizeof(char) * (size + 1))))
return (NULL);
number[size] = 0;
--size;
while (size >= 0)
{
number[size] = '0' + (long_n % 10);
--size;
long_n /= 10;
}
return (number);
}

72
ft_printf/libft/libft.h Normal file
View File

@ -0,0 +1,72 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* libft.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pbonilla <eirodeis.lepnj@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/09 17:31:59 by pbonilla #+# #+# */
/* Updated: 2021/03/19 19:07:47 by pbonilla ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef LIBFT_H
# define LIBFT_H
# include <unistd.h>
# include <stdlib.h>
void *ft_memset(void *s, int c, size_t n);
void ft_bzero(void *s, size_t n);
void *ft_memcpy(void *dest, const void *src, size_t n);
void *ft_memccpy(void *dest, const void *src, int c, size_t n);
void *ft_memmove(void *dest, const void *src, size_t n);
void *ft_memchr(const void *s, int c, size_t n);
int ft_memcmp(const void *s1, const void *s2, size_t n);
size_t ft_strlen(const char *s);
int ft_isalpha(int c);
int ft_isalnum(int c);
int ft_isdigit(int c);
int ft_isascii(int c);
int ft_isprint(int c);
int ft_toupper(int c);
int ft_tolower(int c);
char *ft_strchr(const char *s, int c);
char *ft_strrchr(const char *s, int c);
int ft_strcmp(const char *s1, const char *s2);
int ft_strncmp(const char *s1, const char *s2, size_t n);
size_t ft_strlcpy(char *dst, const char *src, size_t size);
size_t ft_strlcat(char *dst, const char *src, size_t size);
char *ft_strnstr(const char *big, const char *little, size_t len);
int ft_atoi(const char *nptr);
char *ft_substr(char const *s, unsigned int start, size_t len);
char *ft_strjoin(char const *s1, char const *s2);
char *ft_u_itoa(unsigned long long n);
char *ft_itoa(int n);
char *ft_strmapi(char const *s, char (*f)(unsigned int, char));
void ft_putchar_fd(char c, int fd);
void ft_putstr_fd(char *s, int fd);
void ft_putnbr_fd(int n, int fd);
void ft_putendl_fd(char *s, int fd);
int ft_instr(char c, char const *set);
char *ft_strtrim(char const *s1, char const *set);
char **ft_split(char const *s, char c);
char *ft_strdup(const char *s);
void *ft_calloc(size_t nmemb, size_t size);
char *ft_convert_base(char *nbr, char *base_from, char *base_to);
char *ft_u_convert(char *nbr, char *base_from, char *base_to);
void ft_rev_int_tab(char *tab, int size);
typedef struct s_list
{
void *content;
struct s_list *next;
} t_list;
t_list *ft_lstnew(void *content);
void ft_lstadd_front(t_list **alst, t_list *newlist);
int ft_lstsize(t_list *lst);
t_list *ft_lstlast(t_list *lst);
void ft_lstadd_back(t_list **alst, t_list *newlist);
void ft_lstdelone(t_list *lst, void (*del)(void*));
void ft_lstclear(t_list **lst, void (*del)(void*));
void ft_lstiter(t_list *lst, void (*f)(void *));
t_list *ft_lstmap(t_list *l, void *(*f)(void *), void (*del)(void *));
#endif

View File

@ -0,0 +1,34 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_char_case.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pbonilla <eirodeis.lepnj@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/03/03 16:34:32 by pbonilla #+# #+# */
/* Updated: 2021/03/19 21:53:46 by pbonilla ### ########.fr */
/* */
/* ************************************************************************** */
#include "../includes/ft_printf.h"
char *ft_char_case(t_param *param, int i)
{
int len;
int pos;
char *s;
len = 1;
pos = 0;
if (param->width > len)
len = param->width;
if (!param->minus)
pos = len - 1;
if (!(s = malloc(sizeof(char) * (len + 1))))
return (NULL);
s[len] = 0;
ft_memset(s, ' ', len);
s[pos] = i;
param->len = len;
return (s);
}

View File

@ -0,0 +1,67 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_int_case.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pbonilla <eirodeis.lepnj@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/03/03 03:23:01 by pbonilla #+# #+# */
/* Updated: 2021/03/19 19:12:14 by pbonilla ### ########.fr */
/* */
/* ************************************************************************** */
#include "../includes/ft_printf.h"
char *fill_s_int(char *s, int len, char *s_i, t_param *param)
{
int save;
int i;
int test;
test = ft_atoi(s_i);
save = ft_strlen(s_i) - (s_i[0] == '-');
i = ft_strlen(s_i);
while (--len >= 0 && --i >= 0 && s_i[i] != '-')
{
s[len] = s_i[i];
if (test == 0 && param->prec == 0)
s[len] = ' ';
}
while (param->prec-- > save)
s[len--] = '0';
if (param->zero && param->prec != -1)
len = 0;
if (s_i[0] == '-')
s[len] = '-';
free(s_i);
return (s);
}
char *ft_int_case(t_param *param, int i)
{
int save;
int len;
char *s_i;
char *s;
if (param->prec > -1 && param->zero)
param->zero = 0;
s_i = ft_itoa(i);
len = ft_strlen(s_i) - (s_i[0] == '-');
if (i == 0 && param->prec == 0)
len = 0;
if (param->prec > len)
len = param->prec;
len += (s_i[0] == '-');
save = len;
if (param->width > len)
len = param->width;
if (!(s = malloc(sizeof(char) * (len + 1))))
return (NULL);
s[len] = 0;
ft_printf_memset(s, len, param);
if (param->minus)
len = save;
s = fill_s_int(s, len, s_i, param);
return (s);
}

View File

@ -0,0 +1,84 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_parser.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pbonilla <eirodeis.lepnj@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/03/03 02:19:59 by pbonilla #+# #+# */
/* Updated: 2021/03/21 20:00:15 by pbonilla ### ########.fr */
/* */
/* ************************************************************************** */
#include "../includes/ft_printf.h"
t_param ft_init_param(void)
{
t_param param;
param.minus = 0;
param.zero = 0;
param.width = 0;
param.prec = -1;
param.type = 0;
param.len = 0;
return (param);
}
int is_valid_type(const char c)
{
return (c == 'c' || c == 's' || c == 'p' || c == 'd' ||
c == 'i' || c == 'u' || c == 'x' || c == 'X' || c == '%');
}
int ft_parse_para2(const char *s, int i, t_param *par, va_list args)
{
if (s[i] == '.')
{
par->prec = 0;
if (s[++i] == '*')
{
par->prec = va_arg(args, int);
++i;
}
else if (s[i] >= '0' && s[i] <= '9')
{
par->prec = ft_atoi(&s[i]);
while (s[i] >= '0' && s[i] <= '9')
++i;
}
}
if (is_valid_type(s[i]))
par->type = (int)s[i];
else
return (-1);
return (i);
}
int ft_parse_param(const char *s, int i, t_param *par, va_list args)
{
while (s[i] == '0' || s[i] == '-')
{
if (s[i] == '0')
par->zero = 1;
else if (s[i] == '-')
par->minus = 1;
++i;
}
if (s[i] >= '0' && s[i] <= '9')
par->width = ft_atoi(&s[i]);
while (s[i] >= '0' && s[i] <= '9')
++i;
if (s[i] == '*')
{
par->width = va_arg(args, int);
++i;
}
if (par->width < 0)
{
par->width *= -1;
par->minus = 1;
}
i = ft_parse_para2(s, i, par, args);
return (i);
}

View File

@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_percent_case.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pbonilla <eirodeis.lepnj@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/03/12 12:21:58 by pbonilla #+# #+# */
/* Updated: 2021/03/21 20:10:25 by pbonilla ### ########.fr */
/* */
/* ************************************************************************** */
#include "../includes/ft_printf.h"
char *ft_percent_case(t_param *param)
{
int len;
int pos;
char *s;
len = 1;
pos = 0;
if (param->width > len)
len = param->width;
if (!param->minus)
pos = len - 1;
if (!(s = malloc(sizeof(char) * (len + 1))))
return (NULL);
s[len] = 0;
ft_printf_memset(s, len, param);
s[pos] = '%';
return (s);
}

View File

@ -0,0 +1,78 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pbonilla <eirodeis.lepnj@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/03/02 21:18:26 by pbonilla #+# #+# */
/* Updated: 2021/03/21 20:10:56 by pbonilla ### ########.fr */
/* */
/* ************************************************************************** */
#include "../includes/ft_printf.h"
int ft_print_param(t_param *param, va_list args, char **buff)
{
if ((char)param->type == 'c')
*buff = ft_char_case(param, va_arg(args, int));
else if ((char)param->type == 's')
*buff = ft_str_case(param, va_arg(args, char *));
else if ((char)param->type == 'p')
*buff = ft_ptr_case(param, va_arg(args, unsigned long long));
else if ((char)param->type == 'd' || (char)param->type == 'i')
*buff = ft_int_case(param, va_arg(args, int));
else if ((char)param->type == 'u')
*buff = ft_ui_case(param, va_arg(args, unsigned int));
else if ((char)param->type == 'x' || (char)param->type == 'X')
*buff = ft_x_case(param, va_arg(args, unsigned long));
else if ((char)param->type == '%')
*buff = ft_percent_case(param);
if (param->type == 'c')
{
write(1, *buff, param->len);
return (param->len);
}
else
ft_putstr_fd(*buff, 1);
return (ft_strlen(*buff));
}
int ft_read_str(const char *s, va_list args)
{
t_param param;
int i;
int nb_chars;
char *buff;
i = -1;
nb_chars = 0;
while (s[++i])
{
buff = NULL;
if (s[i] != '%')
nb_chars += write(1, &s[i], 1);
else if (s[i] == '%' && s[i + 1])
{
param = ft_init_param();
i = ft_parse_param(s, ++i, &param, args);
if (i == -1)
return (-1);
nb_chars += ft_print_param(&param, args, &buff);
if (buff)
free(buff);
}
}
return (nb_chars);
}
int ft_printf(const char *s, ...)
{
va_list args;
int nb_chars;
va_start(args, s);
nb_chars = ft_read_str(s, args);
va_end(args);
return (nb_chars);
}

View File

@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf_memset.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pbonilla <eirodeis.lepnj@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/03/04 05:59:48 by pbonilla #+# #+# */
/* Updated: 2021/03/19 19:13:48 by pbonilla ### ########.fr */
/* */
/* ************************************************************************** */
#include "../includes/ft_printf.h"
void *ft_printf_memset(void *s, size_t n, t_param *param)
{
unsigned char *buff;
unsigned int i;
int c;
buff = s;
i = -1;
c = ' ';
if (param->prec > -1 && param->zero)
param->zero = 0;
if (param->zero && !param->minus)
c = '0';
while (++i != n)
*(buff + i) = c;
s = (void *)buff;
return (s);
}

View File

@ -0,0 +1,63 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_ptr_case.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pbonilla <eirodeis.lepnj@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/03/11 12:54:20 by pbonilla #+# #+# */
/* Updated: 2021/03/21 20:53:18 by pbonilla ### ########.fr */
/* */
/* ************************************************************************** */
#include "../includes/ft_printf.h"
int zero_case(t_param *param, unsigned long long i)
{
if (param->prec == 0 && i == 0)
return (0);
return (1);
}
char *fill_s_ptr(unsigned long long j, int len, char *s_x,
t_param *param)
{
char *s;
int i;
if (!(s = malloc(sizeof(char) * (len + 1))))
return (NULL);
s[len] = 0;
ft_printf_memset(s, len, param);
if (param->minus)
len = ft_strlen(s_x) + 1 + zero_case(param, j);
i = ft_strlen(s_x);
while (--len >= 0 && --i >= 0)
{
s[len] = s_x[i];
if (j == 0 && param->prec == 0)
{
s[len] = ' ';
++len;
}
}
s[len] = 'x';
s[--len] = '0';
free(s_x);
return (s);
}
char *ft_ptr_case(t_param *param, unsigned long long i)
{
char *s_x;
char *s_ul;
int len;
s_ul = ft_u_itoa(i);
s_x = ft_u_convert(s_ul, "0123456789", "0123456789abcdef");
free(s_ul);
len = ft_strlen(s_x) + 1 + zero_case(param, i);
if (param->width > len)
len = param->width;
return (fill_s_ptr(i, len, s_x, param));
}

View File

@ -0,0 +1,65 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_str_case.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pbonilla <eirodeis.lepnj@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/03/04 05:25:41 by pbonilla #+# #+# */
/* Updated: 2021/03/19 19:18:42 by pbonilla ### ########.fr */
/* */
/* ************************************************************************** */
#include "../includes/ft_printf.h"
char *fill_s_str(char *s, int len, char *s_arg, t_param *param)
{
int i;
i = ft_strlen(s_arg);
if (param->prec != -1 && param->prec < i)
i = param->prec;
while (--len >= 0 && --i >= 0)
s[len] = s_arg[i];
return (s);
}
void change_par_str(t_param *param)
{
if (param->width < 0 && param->width != -1)
{
param->width *= -1;
param->minus = 1;
}
if (param->prec < -1)
param->prec = -1;
}
char *ft_str_case(t_param *param, char *str)
{
int save;
int len;
char *s_arg;
char *s;
change_par_str(param);
s_arg = str;
if (!str)
s_arg = ft_strdup("(null)");
len = ft_strlen(s_arg);
if (param->prec != -1 && param->prec < len)
len = param->prec;
save = len;
if (param->width > len)
len = param->width;
if (!(s = malloc(sizeof(char) * len + 1)))
return (NULL);
s[len] = 0;
ft_printf_memset(s, len, param);
if (param->minus)
len = save;
s = fill_s_str(s, len, s_arg, param);
if (!str)
free(s_arg);
return (s);
}

View File

@ -0,0 +1,60 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_ui_case.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pbonilla <eirodeis.lepnj@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/03/08 06:18:38 by pbonilla #+# #+# */
/* Updated: 2021/03/20 20:18:26 by pbonilla ### ########.fr */
/* */
/* ************************************************************************** */
#include "../includes/ft_printf.h"
char *fill_s_uint(char *s, int len, char *s_ui, t_param *param)
{
int save;
int i;
save = ft_strlen(s_ui);
i = save;
while (--len >= 0 && --i >= 0)
{
s[len] = s_ui[i];
if (s_ui[0] == '0' && param->prec == 0)
s[len] = ' ';
}
while (param->prec-- > save)
s[len--] = '0';
return (s);
}
char *ft_ui_case(t_param *param, unsigned int i)
{
int save;
int len;
char *s_ui;
char *s;
if (param->prec != -1 && param->zero)
param->zero = 0;
s_ui = ft_u_itoa(i);
len = ft_strlen(s_ui);
if (i == 0 && param->prec == 0)
len = 0;
if (param->prec > len)
len = param->prec;
save = len;
if (param->width > len)
len = param->width;
if (!(s = malloc(sizeof(char) * (len + 1))))
return (NULL);
s[len] = 0;
ft_printf_memset(s, len, param);
if (param->minus)
len = save;
s = fill_s_uint(s, len, s_ui, param);
free(s_ui);
return (s);
}

View File

@ -0,0 +1,64 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_x_case.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pbonilla <eirodeis.lepnj@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/03/08 16:22:32 by pbonilla #+# #+# */
/* Updated: 2021/03/21 20:38:30 by pbonilla ### ########.fr */
/* */
/* ************************************************************************** */
#include "../includes/ft_printf.h"
char *fill_s_x(int len, int save, char *s_x, t_param *param)
{
char *s;
int size;
int i;
int test;
test = ft_atoi(s_x);
if (!(s = malloc(sizeof(char) * (len + 1))))
return (NULL);
s[len] = 0;
ft_printf_memset(s, len, param);
size = ft_strlen(s_x);
i = size;
if (param->minus)
len = save;
while (--len >= 0 && --i >= 0)
{
if (!(s_x[i] == '0' && !param->prec && !test && s_x[0] == '0'))
s[len] = s_x[i];
}
while (param->prec-- > size)
s[len--] = '0';
free(s_x);
return (s);
}
char *ft_x_case(t_param *param, unsigned long i)
{
int save;
int len;
char *s_ui;
char *s_x;
s_ui = ft_u_itoa(i);
if (param->type == 'x')
s_x = ft_convert_base(s_ui, "0123456789", "0123456789abcdef");
else
s_x = ft_convert_base(s_ui, "0123456789", "0123456789ABCDEF");
free(s_ui);
len = ft_strlen(s_x);
if (i == 0 && param->prec == 0)
len = 0;
if (param->prec > len)
len = param->prec;
save = len;
if (param->width > len)
len = param->width;
return (fill_s_x(len, save, s_x, param));
}

BIN
resources/sample Executable file

Binary file not shown.

7
resources/sample.c Normal file
View File

@ -0,0 +1,7 @@
#include <stdio.h>
int
main(void) {
printf("Hello, World!\n");
return (0x0);
}

BIN
resources/sample64 Executable file

Binary file not shown.

BIN
resources/woody Executable file

Binary file not shown.

4
srcs/main.c Normal file
View File

@ -0,0 +1,4 @@
int main()
{
}