diff options
| -rw-r--r-- | Makefile | 25 | ||||
| -rw-r--r-- | ft_printf.c | 55 | ||||
| -rw-r--r-- | ft_printf.h | 6 |
3 files changed, 86 insertions, 0 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..ad9d94d --- /dev/null +++ b/Makefile @@ -0,0 +1,25 @@ +CC = gcc +CCFLAGS = -Wall -Wextra #-Werror + +RM = rm -f + +NAME = ft_printf +SRC = ft_printf.c +OBJ = $(SRC:.c=.o) +INCLUDE = ft_printf.h + +all: $(NAME) + +$(NAME): $(OBJ) $(INCLUDE) + $(CC) $(CCFLAGS) -o $@ $(OBJ) + +%.o: %.c + $(CC) $(CCFLAGS) -c -o $@ $< + +clean: + $(RM) $(OBJ) + +fclean: clean + $(RM) $(OBJ) + +re: fclean all diff --git a/ft_printf.c b/ft_printf.c new file mode 100644 index 0000000..9817e6c --- /dev/null +++ b/ft_printf.c @@ -0,0 +1,55 @@ +#include <unistd.h> +#include <stdlib.h> +#include <stdarg.h> +#include "ft_printf.h" + +int ft_printf(const char *format, ...) +{ + int i; + va_list ap; + + va_start(ap, format); + i = -1; + while (format[++i]) + { + if (format[i] == '%') + { + switch (format[++i]) + { + case 'c': + ft_putchar(va_arg(ap, char)); + break; + case 's': + ft_putstr(va_arg(ap, char*)); + break; + case 'p': + print_addr(va_arg(ap, void*)); + break; + case 'd': + ft_putnbr(va_arg(ap, int)); + break; + case 'i': + ft_putnbr(va_arg(ap, int)); + break; + case 'u': + ft_putunbr(va_arg(ap, unsigned int)); + break; + case 'x': + ft_putxnbr(va_arg(ap, int)); + break; + case 'X': + break; + } + } + else + write(STDOUT_FILENO, format + i, 1); + } + va_end(ap); + return (0); +} + +int main() +{ + ft_printf("bonjour\n"); + return 0; +} diff --git a/ft_printf.h b/ft_printf.h new file mode 100644 index 0000000..f3c09ab --- /dev/null +++ b/ft_printf.h @@ -0,0 +1,6 @@ +#ifndef FT_PRINTF_H +# define FT_PRINTF_H + +int ft_printf(const char *format, ...); + +#endif |
