Reuse ft_isdigit and ft_strchr from libft
This commit is contained in:
9
Makefile
9
Makefile
@@ -6,7 +6,7 @@
|
||||
# By: gbaconni@student.42lausanne.ch +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2022/01/18 15:11:16 by gbaconni #+# #+# #
|
||||
# Updated: 2022/04/29 08:10:10 by gbaconni ### lausanne.ch #
|
||||
# Updated: 2022/04/29 08:44:41 by gbaconni ### lausanne.ch #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
#
|
||||
@@ -116,9 +116,15 @@ test: bonus
|
||||
ifeq ($(KERNEL),Linux)
|
||||
test2: leak
|
||||
@$(MAKE) test LEAK=1 DEBUG=$(DEBUG) FAST=$(FAST)
|
||||
|
||||
test21: leak
|
||||
@$(MAKE) test42 LEAK=1 DEBUG=$(DEBUG) FAST=$(FAST)
|
||||
else
|
||||
test2: debug
|
||||
@$(MAKE) test DEBUG=1 LEAK=$(LEAKS) FAST=$(FAST)
|
||||
|
||||
test21: debug
|
||||
@$(MAKE) test42 DEBUG=1 LEAK=$(LEAKS) FAST=$(FAST)
|
||||
endif
|
||||
|
||||
test3: fast
|
||||
@@ -131,7 +137,6 @@ test42: bonus
|
||||
@$(PREFIX) ./$(NAME) "Preceding with blanks: %10d \n" 1977
|
||||
@$(PREFIX) ./$(NAME) "Preceding with zeros: %010d \n" 1977
|
||||
@$(PREFIX) ./$(NAME) "Some different radices: %d %x %#x\n" 100 100 100
|
||||
@$(PREFIX) ./$(NAME) "Width trick: %*d \n" 5 10
|
||||
|
||||
watch: fclean
|
||||
@read -p "cmd: " cmd; while :; do clear; date "+%F %T (every 2.0s)"; echo; sh -c "$${cmd} 2>&1" | tail -n 10 || true; sleep 2; done
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
# By: gbaconni@student.42lausanne.ch +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2022/01/18 15:11:16 by gbaconni #+# #+# #
|
||||
# Updated: 2022/04/26 19:15:34 by gbaconni ### lausanne.ch #
|
||||
# Updated: 2022/04/29 08:39:34 by gbaconni ### lausanne.ch #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
#
|
||||
@@ -29,6 +29,8 @@ SRC = \
|
||||
$(LIBFT)/ft_bzero.c \
|
||||
$(LIBFT)/ft_calloc.c \
|
||||
$(LIBFT)/ft_strlen.c \
|
||||
$(LIBFT)/ft_strchr.c \
|
||||
$(LIBFT)/ft_isdigit.c \
|
||||
$(LIBFT)/ft_itoa.c \
|
||||
ft_eoflags.c \
|
||||
ft_skipchars.c \
|
||||
|
||||
53
libftprintf/ft_ischr.c
Normal file
53
libftprintf/ft_ischr.c
Normal file
@@ -0,0 +1,53 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_vprintf_string.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gbaconni@student.42lausanne.ch +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/01/20 11:56:37 by gbaconni #+# #+# */
|
||||
/* Updated: 2022/04/26 18:41:30 by gbaconni ### lausanne.ch */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libftprintf.h"
|
||||
|
||||
int ft_vprintf_string(const char *format, va_list ap)
|
||||
{
|
||||
int ret;
|
||||
char *s;
|
||||
|
||||
(void) format;
|
||||
ret = 0;
|
||||
s = va_arg(ap, char *);
|
||||
if (s == NULL)
|
||||
{
|
||||
ret = ft_puts("(null)");
|
||||
return (ret);
|
||||
}
|
||||
|
||||
const char *f;
|
||||
int precision;
|
||||
int len;
|
||||
int flags;
|
||||
precision = 0;
|
||||
flags = ft_vprintf_flags_bonus(format, ap);
|
||||
(void) flags;
|
||||
f = format;
|
||||
while (*f != '\0')
|
||||
{
|
||||
if (*f >= '0' && *f <= '9')
|
||||
precision = precision * 10 + *f - '0';
|
||||
if (*f == 'c' || *f == 's' || *f == 'p' || *f == 'd' || *f == 'i' || *f == 'u' || *f == 'x' || *f == 'X' || *f == '%')
|
||||
break ;
|
||||
f++;
|
||||
}
|
||||
if (precision > 0)
|
||||
{
|
||||
len = precision - ft_strlen(s);
|
||||
while (len --> 0)
|
||||
ret += ft_putchar(' ');
|
||||
}
|
||||
ret += ft_puts(s);
|
||||
return (ret);
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: gbaconni@student.42lausanne.ch +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/01/20 11:55:02 by gbaconni #+# #+# */
|
||||
/* Updated: 2022/04/26 17:48:37 by gbaconni ### ########.fr */
|
||||
/* Updated: 2022/04/29 08:42:35 by gbaconni ### lausanne.ch */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -42,9 +42,9 @@ int ft_vprintf_decimal(const char *format, va_list ap)
|
||||
f = format;
|
||||
while (*f != '\0')
|
||||
{
|
||||
if (*f >= '0' && *f <= '9')
|
||||
if (ft_isdigit(*f))
|
||||
precision = precision * 10 + *f - '0';
|
||||
if (*f == 'c' || *f == 's' || *f == 'p' || *f == 'd' || *f == 'i' || *f == 'u' || *f == 'x' || *f == 'X' || *f == '%')
|
||||
if (ft_strchr("cspdiuxX%", *f) != NULL)
|
||||
break ;
|
||||
f++;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: gbaconni@student.42lausanne.ch +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/01/20 11:56:37 by gbaconni #+# #+# */
|
||||
/* Updated: 2022/04/26 18:41:30 by gbaconni ### lausanne.ch */
|
||||
/* Updated: 2022/04/29 08:42:02 by gbaconni ### lausanne.ch */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -36,9 +36,9 @@ int ft_vprintf_string(const char *format, va_list ap)
|
||||
f = format;
|
||||
while (*f != '\0')
|
||||
{
|
||||
if (*f >= '0' && *f <= '9')
|
||||
if (ft_isdigit(*f))
|
||||
precision = precision * 10 + *f - '0';
|
||||
if (*f == 'c' || *f == 's' || *f == 'p' || *f == 'd' || *f == 'i' || *f == 'u' || *f == 'x' || *f == 'X' || *f == '%')
|
||||
if (ft_strchr("cspdiuxX%", *f) != NULL)
|
||||
break ;
|
||||
f++;
|
||||
}
|
||||
|
||||
18
libftprintf/libft/ft_isdigit.c
Normal file
18
libftprintf/libft/ft_isdigit.c
Normal file
@@ -0,0 +1,18 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isdigit.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/10/11 14:33:30 by gbaconni #+# #+# */
|
||||
/* Updated: 2021/10/23 16:22:32 by gbaconni ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_isdigit(int c)
|
||||
{
|
||||
return (c >= '0' && c <= '9');
|
||||
}
|
||||
24
libftprintf/libft/ft_strchr.c
Normal file
24
libftprintf/libft/ft_strchr.c
Normal file
@@ -0,0 +1,24 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strchr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/10/11 14:34:33 by gbaconni #+# #+# */
|
||||
/* Updated: 2021/10/23 21:33:09 by gbaconni ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strchr(const char *s, int c)
|
||||
{
|
||||
while (*s != (const char)c)
|
||||
{
|
||||
if (*s == '\0')
|
||||
return (NULL);
|
||||
s++;
|
||||
}
|
||||
return ((char *)s);
|
||||
}
|
||||
4
main.c
4
main.c
@@ -6,7 +6,7 @@
|
||||
/* By: gbaconni@student.42lausanne.ch +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/04/13 06:58:46 by gbaconni #+# #+# */
|
||||
/* Updated: 2022/04/25 07:08:49 by gbaconni ### lausanne.ch */
|
||||
/* Updated: 2022/04/29 08:23:07 by gbaconni ### lausanne.ch */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -53,6 +53,8 @@ int _printf(int (*f)(const char *restrict, ...), \
|
||||
char c;
|
||||
|
||||
ret = 0;
|
||||
if (arg == NULL)
|
||||
return (ret);
|
||||
c = *(format + 1 + ft_skipchars(format + 1, "0123456789# +"));
|
||||
if (c == 'c')
|
||||
ret = (*f)(format, *arg);
|
||||
|
||||
Reference in New Issue
Block a user