1
0

add printf

This commit is contained in:
Adam Joly
2024-02-04 15:26:48 +01:00
parent ec87e27fcf
commit 3952c22f55
10 changed files with 40 additions and 67 deletions

View File

@ -6,7 +6,7 @@
# By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2023/11/01 11:03:22 by adjoly #+# #+# #
# Updated: 2024/02/04 15:03:34 by adjoly ### ########.fr #
# Updated: 2024/02/04 15:15:14 by adjoly ### ########.fr #
# #
# **************************************************************************** #
@ -69,7 +69,8 @@ FLAGS = -Werror -Wall -Wextra -g
HEADERS = libft.h
LIB = print/printf/libftprintf.a
LIB = print/printf/libftprintf.a \
io/get_next_line/get_next_line.a
$(NAME): $(OBJS)
make -C io/get_next_line/

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/01 17:12:00 by adjoly #+# #+# */
/* Updated: 2024/02/04 14:26:01 by adjoly ### ########.fr */
/* Updated: 2024/02/04 15:24:21 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -23,6 +23,6 @@
char *get_next_line(int fd);
char *ft_strjoin_gnl(char *s1, char *s2);
void *ft_calloc(size_t nmemb, size_t size);
size_t ft_strlen(char *s);
size_t ft_strlen(const char *s);
#endif

View File

@ -3,10 +3,10 @@
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ #
# By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2023/11/17 12:35:27 by adjoly #+# #+# #
# Updated: 2023/11/20 15:55:52 by adjoly ### ########.fr #
# Updated: 2024/02/04 15:18:46 by adjoly ### ########.fr #
# #
# **************************************************************************** #
@ -19,7 +19,7 @@ SRCS = ft_printf.c \
ft_putnbr.c \
ft_putnbrbase.c \
ft_putstr.c \
ft_strlen.c \
../../str/ft_strlen.c \
OBJS = $(SRCS:.c=.o)

View File

@ -3,10 +3,10 @@
/* ::: :::::::: */
/* ft_printf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/17 16:48:37 by adjoly #+# #+# */
/* Updated: 2023/12/06 14:27:05 by adjoly ### ########.fr */
/* Updated: 2024/02/04 15:23:15 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -44,21 +44,21 @@ int ft_printconversion(char conversion, va_list args)
count = 0;
if (conversion == '%')
count = ft_putchar('%');
count = ft_putchar_p('%');
else if (conversion == 's')
count = ft_putstr(va_arg(args, char *));
count = ft_putstr_p(va_arg(args, char *));
else if (conversion == 'c')
count = ft_putchar(va_arg(args, int));
count = ft_putchar_p(va_arg(args, int));
else if (conversion == 'i' || conversion == 'd')
count = ft_putnbr(va_arg(args, int));
count = ft_putnbr_p(va_arg(args, int));
else if (conversion == 'u')
count = ft_putnbrulong(va_arg(args, unsigned int));
else if (conversion == 'p')
count = ft_putaddr(va_arg(args, void *));
else if (conversion == 'x')
count = ft_putnbrbase(va_arg(args, unsigned long), "0123456789abcdef");
count = ft_putnbrbase_pf(va_arg(args, unsigned long), "0123456789abcdef");
else if (conversion == 'X')
count = ft_putnbrbase(va_arg(args, unsigned long), "0123456789ABCDEF");
count = ft_putnbrbase_pf(va_arg(args, unsigned long), "0123456789ABCDEF");
return (count);
}
@ -84,7 +84,7 @@ int ft_printf(const char *format, ...)
return (-1);
}
else
count += ft_putchar(format[i]);
count += ft_putchar_p(format[i]);
i++;
}
va_end(args);

View File

@ -3,10 +3,10 @@
/* ::: :::::::: */
/* ft_printf.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/17 16:50:36 by adjoly #+# #+# */
/* Updated: 2023/11/22 14:00:38 by adjoly ### ########.fr */
/* Updated: 2024/02/04 15:23:39 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -22,12 +22,12 @@ int ft_printconversion(char conversion, va_list args);
int ft_putnbrulong(unsigned int n);
int ft_putaddr(void *ptr);
int ft_putstr(char *s);
int ft_putstr_p(char *s);
int ft_putnbrbase_p(unsigned long int n, char *base);
int ft_putnbrbase(unsigned int n, char *base);
int ft_putchar(char c);
int ft_putnbr(int n);
int ft_putnbrbase_pf(unsigned int n, char *base);
int ft_putchar_p(char c);
int ft_putnbr_p(int n);
size_t ft_strlen(const char *s);
#endif

View File

@ -3,16 +3,16 @@
/* ::: :::::::: */
/* ft_putchar.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/18 10:49:00 by adjoly #+# #+# */
/* Updated: 2023/11/22 11:07:22 by adjoly ### ########.fr */
/* Updated: 2024/02/04 15:17:42 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_putchar(char c)
int ft_putchar_p(char c)
{
write(1, &c, 1);
return (1);

View File

@ -3,16 +3,16 @@
/* ::: :::::::: */
/* ft_putnbr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/31 11:52:46 by adjoly #+# #+# */
/* Updated: 2023/11/22 10:51:24 by adjoly ### ########.fr */
/* Updated: 2024/02/04 15:20:26 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_putnbr(int n)
int ft_putnbr_p(int n)
{
unsigned int nbr;
int len;
@ -29,7 +29,7 @@ int ft_putnbr(int n)
len += write(1, &(char){nbr + '0'}, 1);
else
{
len += ft_putnbr(nbr / 10);
len += ft_putnbr_p(nbr / 10);
len += write(1, &(char){nbr % 10 + '0'}, 1);
}
return (len);

View File

@ -3,16 +3,16 @@
/* ::: :::::::: */
/* ft_putnbrbase.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/18 10:57:44 by adjoly #+# #+# */
/* Updated: 2023/11/22 14:02:37 by adjoly ### ########.fr */
/* Updated: 2024/02/04 15:21:56 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_putnbrbase(unsigned int n, char *base)
int ft_putnbrbase_pf(unsigned int n, char *base)
{
unsigned int base_len;
int len;
@ -23,7 +23,7 @@ int ft_putnbrbase(unsigned int n, char *base)
len += write(1, &base[n % base_len], 1);
else
{
len += ft_putnbrbase(n / base_len, base);
len += ft_putnbrbase_pf(n / base_len, base);
len += write(1, &base[n % base_len], 1);
}
return (len);

View File

@ -3,16 +3,16 @@
/* ::: :::::::: */
/* ft_putstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/31 11:45:55 by adjoly #+# #+# */
/* Updated: 2023/11/20 15:51:38 by adjoly ### ########.fr */
/* Updated: 2024/02/04 15:23:52 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_putstr(char *s)
int ft_putstr_p(char *s)
{
int i;
@ -22,10 +22,5 @@ int ft_putstr(char *s)
write(1, "(null)", 6);
return (6);
}
while (s[i])
{
write(1, &s[i], 1);
i++;
}
return (i);
return (write(1, s, ft_strlen(s)));
}

View File

@ -1,23 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlen.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/30 18:15:57 by adjoly #+# #+# */
/* Updated: 2023/11/20 15:51:51 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
size_t ft_strlen(const char *s)
{
int i;
i = 0;
while (s[i])
i++;
return (i);
}