feat(char): adding function for c / s flags
This commit is contained in:
parent
1b070bfda1
commit
aa04d9a16c
2 changed files with 64 additions and 0 deletions
39
sources/print_char.c
Normal file
39
sources/print_char.c
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* print_char.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/09/18 14:49:02 by rparodi #+# #+# */
|
||||||
|
/* Updated: 2025/09/19 15:39:41 by rparodi ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "ft_printf.h"
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
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));
|
||||||
|
}
|
||||||
25
sources/utils.c
Normal file
25
sources/utils.c
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* utils.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/09/18 15:34:52 by rparodi #+# #+# */
|
||||||
|
/* Updated: 2025/09/19 15:53:15 by rparodi ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
size_t ft_strlen(const char *str)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
if (!str)
|
||||||
|
return (0);
|
||||||
|
i = 0;
|
||||||
|
while (str[i])
|
||||||
|
i++;
|
||||||
|
return (i);
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue