printf args started
This commit is contained in:
7
Makefile
7
Makefile
@ -6,7 +6,7 @@
|
||||
# By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2023/11/17 12:35:27 by adjoly #+# #+# #
|
||||
# Updated: 2023/11/17 14:38:41 by adjoly ### ########.fr #
|
||||
# Updated: 2023/11/17 19:59:14 by adjoly ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
@ -14,13 +14,14 @@ NAME = libftprintf.a
|
||||
|
||||
CC = cc
|
||||
|
||||
SRCS = \
|
||||
SRCS = ft_printf.c\
|
||||
|
||||
|
||||
OBJS = $(SRCS:.c=.o)
|
||||
|
||||
FLAGS = -Werror -Wall -Wextra
|
||||
|
||||
HEADER = libftprintf.h
|
||||
HEADER = libftprintf.h \
|
||||
|
||||
$(NAME): $(OBJS)
|
||||
ar -rcs $(NAME) $(OBJS)
|
||||
|
26
ft_printf.c
26
ft_printf.c
@ -6,17 +6,39 @@
|
||||
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/17 16:48:37 by adjoly #+# #+# */
|
||||
/* Updated: 2023/11/17 17:32:54 by adjoly ### ########.fr */
|
||||
/* Updated: 2023/11/17 20:03:48 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft/libft.h"
|
||||
#include "libftprintf.h"
|
||||
#include <stdarg.h>
|
||||
|
||||
int ft_printf(const char *format, ...)
|
||||
{
|
||||
char *result;
|
||||
int i;
|
||||
int j;
|
||||
va_list args;
|
||||
|
||||
va_start(args, format);
|
||||
|
||||
while (format[i])
|
||||
{
|
||||
if (format[i] == '%')
|
||||
{
|
||||
i++;
|
||||
if (format[i] == '%')
|
||||
ft_putchar_fd('%', 1);
|
||||
else if (format[i] == 's')
|
||||
ft_putstr_fd(va_arg(args, char *), 1);
|
||||
else if (format[i] == 'c')
|
||||
ft_putchar_fd(va_arg(args, char *)[0], 1);
|
||||
else if (format[i] == 'i' || format[i] == 'd')
|
||||
ft_putnbr_fd(va_arg(args, int), 1);
|
||||
}
|
||||
else
|
||||
ft_putchar_fd(format[i], i);
|
||||
i++;
|
||||
}
|
||||
return (ft_strlen(result));
|
||||
}
|
||||
|
1
libft
Submodule
1
libft
Submodule
Submodule libft added at 42f67cc750
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/17 16:50:36 by adjoly #+# #+# */
|
||||
/* Updated: 2023/11/17 16:57:31 by adjoly ### ########.fr */
|
||||
/* Updated: 2023/11/17 19:48:34 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -15,6 +15,7 @@
|
||||
|
||||
# include <stdlib.h>
|
||||
# include <stdarg.h>
|
||||
# include "libft/libft.h"
|
||||
|
||||
int ft_printf(const char *format, ...);
|
||||
|
||||
|
Reference in New Issue
Block a user