From aa04d9a16cacd7cf36855b2c58fc95915d9cd1a9 Mon Sep 17 00:00:00 2001 From: Raphael Date: Fri, 19 Sep 2025 16:12:52 +0200 Subject: [PATCH] feat(char): adding function for c / s flags --- sources/print_char.c | 39 +++++++++++++++++++++++++++++++++++++++ sources/utils.c | 25 +++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 sources/print_char.c create mode 100644 sources/utils.c diff --git a/sources/print_char.c b/sources/print_char.c new file mode 100644 index 0000000..b559e77 --- /dev/null +++ b/sources/print_char.c @@ -0,0 +1,39 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* print_char.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/09/18 14:49:02 by rparodi #+# #+# */ +/* Updated: 2025/09/19 15:39:41 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_printf.h" +#include +#include +#include +#include + +int flag_c(va_list args, int fd) +{ + const char character = va_arg(args, int); + + return (write(fd, &character, 1)); +} + +int flag_s(va_list args, int fd) +{ + const char *string = va_arg(args, char *); + + if (string == NULL) + return (write(fd, "(null)", 6)); + return (write(fd, string, ft_strlen(string))); +} + +int flag_percent(va_list args, int fd) +{ + (void)args; + return (write(fd, "%", 1)); +} diff --git a/sources/utils.c b/sources/utils.c new file mode 100644 index 0000000..0dc8f27 --- /dev/null +++ b/sources/utils.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* utils.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/09/18 15:34:52 by rparodi #+# #+# */ +/* Updated: 2025/09/19 15:53:15 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +size_t ft_strlen(const char *str) +{ + size_t i; + + if (!str) + return (0); + i = 0; + while (str[i]) + i++; + return (i); +}