Mandatory tested and finish
This commit is contained in:
@@ -6,32 +6,32 @@
|
||||
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/11/17 10:54:03 by dgaillet #+# #+# */
|
||||
/* Updated: 2025/11/17 12:35:20 by dgaillet ### ########lyon.fr */
|
||||
/* Updated: 2025/11/17 12:47:03 by dgaillet ### ########lyon.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <unistd.h>
|
||||
#include "../include/ft_printf.h"
|
||||
#include "ft_printf.h"
|
||||
|
||||
static int ft_print_arg(char c, va_list args)
|
||||
{
|
||||
if (c == 'c')
|
||||
return (print_char(va_arg(args, int)));
|
||||
else if (c == 's')
|
||||
return (print_str(va_arg(args, char *)));
|
||||
return (print_str(va_arg(args, char *)));
|
||||
else if (c == 'p')
|
||||
return (print_pointer(va_arg(args, unsigned long long)));
|
||||
return (print_pointer(va_arg(args, unsigned long long)));
|
||||
else if (c == 'd' || c == 'i')
|
||||
return (print_number(va_arg(args, int)));
|
||||
return (print_number(va_arg(args, int)));
|
||||
else if (c == 'u')
|
||||
return (print_unsigned(va_arg(args, unsigned int)));
|
||||
return (print_unsigned(va_arg(args, unsigned int)));
|
||||
else if (c == 'x')
|
||||
return (print_hex(va_arg(args, unsigned int), 0));
|
||||
return (print_hex(va_arg(args, unsigned int), 0));
|
||||
else if (c == 'X')
|
||||
return (print_hex(va_arg(args, unsigned int), 1));
|
||||
return (print_hex(va_arg(args, unsigned int), 1));
|
||||
else if (c == '%')
|
||||
return (print_char('%'));
|
||||
return (print_char('%'));
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ int ft_printf(const char *first_arg, ...)
|
||||
{
|
||||
if (first_arg[i] == '%')
|
||||
{
|
||||
i++;
|
||||
i++;
|
||||
nb_print += ft_print_arg(first_arg[i], args);
|
||||
}
|
||||
else
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
src/ft_printf.o: src/ft_printf.c src/../include/ft_printf.h
|
||||
src/../include/ft_printf.h:
|
||||
BIN
src/ft_printf.o
BIN
src/ft_printf.o
Binary file not shown.
@@ -6,11 +6,11 @@
|
||||
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/11/17 12:16:44 by dgaillet #+# #+# */
|
||||
/* Updated: 2025/11/17 12:17:14 by dgaillet ### ########lyon.fr */
|
||||
/* Updated: 2025/11/17 12:43:17 by dgaillet ### ########lyon.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../libft/libft.h"
|
||||
#include "libft.h"
|
||||
|
||||
int ft_putnbr_base(unsigned long long nbr, char *base, int base_size)
|
||||
{
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
src/ft_putnbr_base.o: src/ft_putnbr_base.c src/../libft/libft.h
|
||||
src/../libft/libft.h:
|
||||
Binary file not shown.
@@ -6,13 +6,13 @@
|
||||
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/11/17 11:56:36 by dgaillet #+# #+# */
|
||||
/* Updated: 2025/11/17 12:01:47 by dgaillet ### ########lyon.fr */
|
||||
/* Updated: 2025/11/17 12:45:57 by dgaillet ### ########lyon.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
int print_char(char c)
|
||||
int print_char(char c)
|
||||
{
|
||||
return (write(1, &c, 1));
|
||||
}
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
src/print_char.o: src/print_char.c
|
||||
BIN
src/print_char.o
BIN
src/print_char.o
Binary file not shown.
@@ -6,11 +6,11 @@
|
||||
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/11/17 12:06:35 by dgaillet #+# #+# */
|
||||
/* Updated: 2025/11/17 12:38:35 by dgaillet ### ########lyon.fr */
|
||||
/* Updated: 2025/11/17 12:46:47 by dgaillet ### ########lyon.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../include/ft_printf.h"
|
||||
#include "ft_printf.h"
|
||||
#include <unistd.h>
|
||||
|
||||
int print_hex(unsigned long long nbr, int upper)
|
||||
@@ -21,5 +21,4 @@ int print_hex(unsigned long long nbr, int upper)
|
||||
return (ft_putnbr_base(nbr, "0123456789ABCDEF", 16));
|
||||
else
|
||||
return (ft_putnbr_base(nbr, "0123456789abcdef", 16));
|
||||
|
||||
}
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
src/print_hex.o: src/print_hex.c src/../include/ft_printf.h
|
||||
src/../include/ft_printf.h:
|
||||
BIN
src/print_hex.o
BIN
src/print_hex.o
Binary file not shown.
@@ -6,21 +6,24 @@
|
||||
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/11/17 12:26:23 by dgaillet #+# #+# */
|
||||
/* Updated: 2025/11/17 12:31:22 by dgaillet ### ########lyon.fr */
|
||||
/* Updated: 2025/11/17 12:56:40 by dgaillet ### ########lyon.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../include/ft_printf.h"
|
||||
#include "ft_printf.h"
|
||||
#include <unistd.h>
|
||||
|
||||
int print_number(int nbr)
|
||||
{
|
||||
unsigned int p_nbr;
|
||||
|
||||
if (nbr == 0)
|
||||
return (write(1, "0", 1));
|
||||
if (nbr < 0)
|
||||
{
|
||||
write(1, "-", 1);
|
||||
return (1 + ft_putnbr_base(nbr * -1, "0123456789", 10));
|
||||
p_nbr = nbr * -1;
|
||||
return (1 + ft_putnbr_base(p_nbr, "0123456789", 10));
|
||||
}
|
||||
return (ft_putnbr_base(nbr, "0123456789", 10));
|
||||
}
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
src/print_number.o: src/print_number.c src/../include/ft_printf.h
|
||||
src/../include/ft_printf.h:
|
||||
Binary file not shown.
@@ -6,15 +6,20 @@
|
||||
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/11/17 12:19:16 by dgaillet #+# #+# */
|
||||
/* Updated: 2025/11/17 12:25:20 by dgaillet ### ########lyon.fr */
|
||||
/* Updated: 2025/11/17 12:53:27 by dgaillet ### ########lyon.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../libft/libft.h"
|
||||
#include "../include/ft_printf.h"
|
||||
#include "libft.h"
|
||||
#include "ft_printf.h"
|
||||
|
||||
int print_pointer(unsigned long long p)
|
||||
{
|
||||
if (!p)
|
||||
{
|
||||
ft_putstr_fd("(nil)", 1);
|
||||
return (5);
|
||||
}
|
||||
ft_putstr_fd("0x", 1);
|
||||
return (2 + ft_putnbr_base(p, "0123456789abcdef", 16));
|
||||
}
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
src/print_pointer.o: src/print_pointer.c src/../libft/libft.h \
|
||||
src/../include/ft_printf.h
|
||||
src/../libft/libft.h:
|
||||
src/../include/ft_printf.h:
|
||||
Binary file not shown.
@@ -6,14 +6,19 @@
|
||||
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/11/17 12:02:03 by dgaillet #+# #+# */
|
||||
/* Updated: 2025/11/17 12:03:27 by dgaillet ### ########lyon.fr */
|
||||
/* Updated: 2025/11/17 12:51:56 by dgaillet ### ########lyon.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../libft/libft.h"
|
||||
#include "libft.h"
|
||||
|
||||
int print_str(char *str)
|
||||
{
|
||||
if (!str)
|
||||
{
|
||||
ft_putstr_fd("(null)", 1);
|
||||
return (6);
|
||||
}
|
||||
ft_putstr_fd(str, 1);
|
||||
return (ft_strlen(str));
|
||||
}
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
src/print_str.o: src/print_str.c src/../libft/libft.h
|
||||
src/../libft/libft.h:
|
||||
BIN
src/print_str.o
BIN
src/print_str.o
Binary file not shown.
@@ -6,11 +6,11 @@
|
||||
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/11/17 12:26:23 by dgaillet #+# #+# */
|
||||
/* Updated: 2025/11/17 12:34:00 by dgaillet ### ########lyon.fr */
|
||||
/* Updated: 2025/11/17 12:44:47 by dgaillet ### ########lyon.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../include/ft_printf.h"
|
||||
#include "ft_printf.h"
|
||||
#include <unistd.h>
|
||||
|
||||
int print_unsigned(unsigned int nbr)
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
src/print_unsigned.o: src/print_unsigned.c src/../include/ft_printf.h
|
||||
src/../include/ft_printf.h:
|
||||
Binary file not shown.
Reference in New Issue
Block a user