v1
This commit is contained in:
		
							
								
								
									
										1
									
								
								42-printf-tester
									
									
									
									
									
										Submodule
									
								
							
							
								
								
								
								
								
							
						
						
									
										1
									
								
								42-printf-tester
									
									
									
									
									
										Submodule
									
								
							 Submodule 42-printf-tester added at b6aeed792a
									
								
							
							
								
								
									
										19
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								Makefile
									
									
									
									
									
								
							| @ -6,10 +6,25 @@ | |||||||
| #    By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+         # | #    By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+         # | ||||||
| #                                                 +#+#+#+#+#+   +#+            # | #                                                 +#+#+#+#+#+   +#+            # | ||||||
| #    Created: 2022/09/27 08:39:27 by cchauvet          #+#    #+#              # | #    Created: 2022/09/27 08:39:27 by cchauvet          #+#    #+#              # | ||||||
| #    Updated: 2022/10/06 16:37:11 by cchauvet         ###   ########.fr        # | #    Updated: 2022/10/10 14:34:40 by cchauvet         ###   ########.fr        # | ||||||
| #                                                                              # | #                                                                              # | ||||||
| # **************************************************************************** # | # **************************************************************************** # | ||||||
| SRCS   =  | SRCS   = ft_ctoa.c \ | ||||||
|  | 		 ft_itoa.c \ | ||||||
|  | 		 ft_ltoabase.c \ | ||||||
|  | 		 ft_printf.c \ | ||||||
|  | 		 ft_ptoa.c \ | ||||||
|  | 		 ft_putchar_fd.c \ | ||||||
|  | 		 ft_putendl_fd.c \ | ||||||
|  | 		 ft_putstr_fd.c \ | ||||||
|  | 		 ft_strchr.c \ | ||||||
|  | 		 ft_strdup.c \ | ||||||
|  | 		 ft_strjoin.c \ | ||||||
|  | 		 ft_strlen.c \ | ||||||
|  | 		 ft_ultoabase.c \ | ||||||
|  | 		 ft_vdprintf.c \ | ||||||
|  | 		 ft_vprintf.c \ | ||||||
|  | 		 ft_vsprintf.c | ||||||
|  |  | ||||||
| OBJS = ${SRCS:.c=.o} | OBJS = ${SRCS:.c=.o} | ||||||
|  |  | ||||||
|  | |||||||
| @ -6,11 +6,11 @@ | |||||||
| /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | ||||||
| /*                                                +#+#+#+#+#+   +#+           */ | /*                                                +#+#+#+#+#+   +#+           */ | ||||||
| /*   Created: 2022/10/05 21:42:53 by cchauvet          #+#    #+#             */ | /*   Created: 2022/10/05 21:42:53 by cchauvet          #+#    #+#             */ | ||||||
| /*   Updated: 2022/10/07 00:49:07 by cchauvet         ###   ########.fr       */ | /*   Updated: 2022/10/10 14:41:19 by cchauvet         ###   ########.fr       */ | ||||||
| /*                                                                            */ | /*                                                                            */ | ||||||
| /* ************************************************************************** */ | /* ************************************************************************** */ | ||||||
|  |  | ||||||
| #include "libftprintf.h" | #include "printf.h" | ||||||
|  |  | ||||||
| char	*ft_ctoa(int c) | char	*ft_ctoa(int c) | ||||||
| { | { | ||||||
|  | |||||||
| @ -6,11 +6,11 @@ | |||||||
| /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | ||||||
| /*                                                +#+#+#+#+#+   +#+           */ | /*                                                +#+#+#+#+#+   +#+           */ | ||||||
| /*   Created: 2022/09/29 13:49:45 by cchauvet          #+#    #+#             */ | /*   Created: 2022/09/29 13:49:45 by cchauvet          #+#    #+#             */ | ||||||
| /*   Updated: 2022/10/06 21:25:27 by cchauvet         ###   ########.fr       */ | /*   Updated: 2022/10/10 14:41:18 by cchauvet         ###   ########.fr       */ | ||||||
| /*                                                                            */ | /*                                                                            */ | ||||||
| /* ************************************************************************** */ | /* ************************************************************************** */ | ||||||
|  |  | ||||||
| #include "libftprintf.h" | #include "printf.h" | ||||||
|  |  | ||||||
| static int	ft_nb_digit(int n) | static int	ft_nb_digit(int n) | ||||||
| { | { | ||||||
|  | |||||||
| @ -1,55 +1,38 @@ | |||||||
| /* ************************************************************************** */ | /* ************************************************************************** */ | ||||||
| /*                                                                            */ | /*                                                                            */ | ||||||
| /*                                                        :::      ::::::::   */ | /*                                                        :::      ::::::::   */ | ||||||
| /*   ft_itoabase.c                                      :+:      :+:    :+:   */ | /*   ft_ltoabase.c                                      :+:      :+:    :+:   */ | ||||||
| /*                                                    +:+ +:+         +:+     */ | /*                                                    +:+ +:+         +:+     */ | ||||||
| /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | ||||||
| /*                                                +#+#+#+#+#+   +#+           */ | /*                                                +#+#+#+#+#+   +#+           */ | ||||||
| /*   Created: 2022/09/29 13:49:45 by cchauvet          #+#    #+#             */ | /*   Created: 2022/10/10 03:26:21 by cchauvet          #+#    #+#             */ | ||||||
| /*   Updated: 2022/10/06 18:22:32 by cchauvet         ###   ########.fr       */ | /*   Updated: 2022/10/10 14:41:28 by cchauvet         ###   ########.fr       */ | ||||||
| /*                                                                            */ | /*                                                                            */ | ||||||
| /* ************************************************************************** */ | /* ************************************************************************** */ | ||||||
| 
 | 
 | ||||||
| #include "libftprintf.h" | #include "printf.h" | ||||||
| 
 | 
 | ||||||
| static size_t	ft_nb_digit(int n, size_t base_size) | char	*ft_ltoabase(long int n, char *base) | ||||||
| { |  | ||||||
| 	int	out; |  | ||||||
| 
 |  | ||||||
| 	out = 0; |  | ||||||
| 	while (n) |  | ||||||
| 	{ |  | ||||||
| 		n /= base_size; |  | ||||||
| 		out++; |  | ||||||
| 	} |  | ||||||
| 	return (out); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| char	*ft_itoabase(int n, char *base) |  | ||||||
| { | { | ||||||
|  | 	char			*mid_out; | ||||||
| 	char			*out; | 	char			*out; | ||||||
| 	unsigned int	nb[2]; | 	unsigned long	nb; | ||||||
| 
 | 
 | ||||||
| 	if (!n) | 	if (base == NULL) | ||||||
| 		return (ft_ctoa(base[0])); | 		return (NULL); | ||||||
| 	nb[0] = ft_nb_digit(n, ft_strlen(base)); |  | ||||||
| 	if (n < 0) | 	if (n < 0) | ||||||
| 	{ | 	{ | ||||||
| 		nb[1] = -n; | 		nb = -n; | ||||||
| 		nb[0]++; | 		mid_out = ft_ultoabase(nb, base); | ||||||
|  | 		if (mid_out == NULL) | ||||||
|  | 			return (NULL); | ||||||
|  | 		out = ft_strjoin("-", mid_out); | ||||||
|  | 		free(mid_out); | ||||||
| 	} | 	} | ||||||
| 	else | 	else | ||||||
| 		nb[1] = n; |  | ||||||
| 	out = malloc(sizeof(char) * (nb[0] + 1)); |  | ||||||
| 	if (out == NULL) |  | ||||||
| 		return (NULL); |  | ||||||
| 	out[nb[0]--] = 0; |  | ||||||
| 	if (n < 0) |  | ||||||
| 		out[0] = '-'; |  | ||||||
| 	while (nb[1]) |  | ||||||
| 	{ | 	{ | ||||||
| 		out[nb[0]--] = base[nb[1] % ft_strlen(base)]; | 		nb = n; | ||||||
| 		nb[1] /= ft_strlen(base); | 		return (ft_ultoabase(nb, base)); | ||||||
| 	} | 	} | ||||||
| 	return (out); | 	return (out); | ||||||
| } | } | ||||||
							
								
								
									
										
											BIN
										
									
								
								ft_ltoabase.o
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								ft_ltoabase.o
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| @ -6,18 +6,19 @@ | |||||||
| /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | ||||||
| /*                                                +#+#+#+#+#+   +#+           */ | /*                                                +#+#+#+#+#+   +#+           */ | ||||||
| /*   Created: 2022/10/06 22:01:28 by cchauvet          #+#    #+#             */ | /*   Created: 2022/10/06 22:01:28 by cchauvet          #+#    #+#             */ | ||||||
| /*   Updated: 2022/10/07 01:43:13 by cchauvet         ###   ########.fr       */ | /*   Updated: 2022/10/10 17:34:18 by cchauvet         ###   ########.fr       */ | ||||||
| /*                                                                            */ | /*                                                                            */ | ||||||
| /* ************************************************************************** */ | /* ************************************************************************** */ | ||||||
|  |  | ||||||
| #include "libftprintf.h" | #include "printf.h" | ||||||
|  |  | ||||||
| int	ft_printf(const char *s, ...) | int	ft_printf(const char *s, ...) | ||||||
| { | { | ||||||
| 	va_list	va; | 	va_list	va; | ||||||
|  | 	int		i; | ||||||
|  |  | ||||||
| 	va_start(va, s); | 	va_start(va, s); | ||||||
| 	ft_vdprintf(1, s, va); | 	i = ft_vdprintf(1, s, va); | ||||||
| 	va_end(va); | 	va_end(va); | ||||||
| 	return (ft_strlen(s)); | 	return (i); | ||||||
| } | } | ||||||
|  | |||||||
							
								
								
									
										
											BIN
										
									
								
								ft_printf.o
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								ft_printf.o
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										1
									
								
								ft_printf_tester
									
									
									
									
									
										Submodule
									
								
							
							
								
								
								
								
								
							
						
						
									
										1
									
								
								ft_printf_tester
									
									
									
									
									
										Submodule
									
								
							 Submodule ft_printf_tester added at a053a3500c
									
								
							
							
								
								
									
										16
									
								
								ft_ptoa.c
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								ft_ptoa.c
									
									
									
									
									
								
							| @ -6,11 +6,11 @@ | |||||||
| /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | ||||||
| /*                                                +#+#+#+#+#+   +#+           */ | /*                                                +#+#+#+#+#+   +#+           */ | ||||||
| /*   Created: 2022/10/06 17:41:04 by cchauvet          #+#    #+#             */ | /*   Created: 2022/10/06 17:41:04 by cchauvet          #+#    #+#             */ | ||||||
| /*   Updated: 2022/10/06 21:44:49 by cchauvet         ###   ########.fr       */ | /*   Updated: 2022/10/10 15:54:00 by cchauvet         ###   ########.fr       */ | ||||||
| /*                                                                            */ | /*                                                                            */ | ||||||
| /* ************************************************************************** */ | /* ************************************************************************** */ | ||||||
|  |  | ||||||
| #include "libftprintf.h" | #include "printf.h" | ||||||
|  |  | ||||||
| char	*ft_ptoa(void *ptr) | char	*ft_ptoa(void *ptr) | ||||||
| { | { | ||||||
| @ -19,15 +19,19 @@ char	*ft_ptoa(void *ptr) | |||||||
| 	char			*out; | 	char			*out; | ||||||
| 	char			*s; | 	char			*s; | ||||||
|  |  | ||||||
|  | 	if (ptr == NULL) | ||||||
|  | 		return (ft_strdup("(nil)")); | ||||||
| 	address = (unsigned long) ptr; | 	address = (unsigned long) ptr; | ||||||
| 	s = ft_itoabase(address, "0123456789ABCDEF"); | 	s = ft_ultoabase(address, "0123456789abcdef"); | ||||||
| 	out = malloc(22 * sizeof(char *)); | 	out = malloc((ft_strlen(s) + 2) * sizeof(char *)); | ||||||
| 	out = "0x"; | 	out[ft_strlen(s) + 2] = 0; | ||||||
|  | 	out[0] = '0'; | ||||||
|  | 	out[1] = 'x'; | ||||||
|  | 	i = 0; | ||||||
| 	while (s[i] != 0) | 	while (s[i] != 0) | ||||||
| 	{ | 	{ | ||||||
| 		out[i + 2] = s[i]; | 		out[i + 2] = s[i]; | ||||||
| 		i++; | 		i++; | ||||||
| 	} | 	} | ||||||
| 	out = 0; |  | ||||||
| 	return (out); | 	return (out); | ||||||
| } | } | ||||||
|  | |||||||
| @ -6,11 +6,11 @@ | |||||||
| /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | ||||||
| /*                                                +#+#+#+#+#+   +#+           */ | /*                                                +#+#+#+#+#+   +#+           */ | ||||||
| /*   Created: 2022/09/29 22:23:35 by cchauvet          #+#    #+#             */ | /*   Created: 2022/09/29 22:23:35 by cchauvet          #+#    #+#             */ | ||||||
| /*   Updated: 2022/09/29 22:24:53 by cchauvet         ###   ########.fr       */ | /*   Updated: 2022/10/10 14:41:55 by cchauvet         ###   ########.fr       */ | ||||||
| /*                                                                            */ | /*                                                                            */ | ||||||
| /* ************************************************************************** */ | /* ************************************************************************** */ | ||||||
|  |  | ||||||
| #include "libftprintf.h" | #include "printf.h" | ||||||
|  |  | ||||||
| void	ft_putchar_fd(char c, int fd) | void	ft_putchar_fd(char c, int fd) | ||||||
| { | { | ||||||
|  | |||||||
							
								
								
									
										
											BIN
										
									
								
								ft_putchar_fd.o
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								ft_putchar_fd.o
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| @ -6,11 +6,11 @@ | |||||||
| /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | ||||||
| /*                                                +#+#+#+#+#+   +#+           */ | /*                                                +#+#+#+#+#+   +#+           */ | ||||||
| /*   Created: 2022/09/29 22:26:36 by cchauvet          #+#    #+#             */ | /*   Created: 2022/09/29 22:26:36 by cchauvet          #+#    #+#             */ | ||||||
| /*   Updated: 2022/09/29 22:43:19 by cchauvet         ###   ########.fr       */ | /*   Updated: 2022/10/10 14:42:06 by cchauvet         ###   ########.fr       */ | ||||||
| /*                                                                            */ | /*                                                                            */ | ||||||
| /* ************************************************************************** */ | /* ************************************************************************** */ | ||||||
|  |  | ||||||
| #include "libftprintf.h" | #include "printf.h" | ||||||
|  |  | ||||||
| void	ft_putendl_fd(char *s, int fd) | void	ft_putendl_fd(char *s, int fd) | ||||||
| { | { | ||||||
|  | |||||||
							
								
								
									
										
											BIN
										
									
								
								ft_putendl_fd.o
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								ft_putendl_fd.o
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| @ -6,11 +6,11 @@ | |||||||
| /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | ||||||
| /*                                                +#+#+#+#+#+   +#+           */ | /*                                                +#+#+#+#+#+   +#+           */ | ||||||
| /*   Created: 2022/09/29 22:25:08 by cchauvet          #+#    #+#             */ | /*   Created: 2022/09/29 22:25:08 by cchauvet          #+#    #+#             */ | ||||||
| /*   Updated: 2022/09/29 22:40:34 by cchauvet         ###   ########.fr       */ | /*   Updated: 2022/10/10 14:42:15 by cchauvet         ###   ########.fr       */ | ||||||
| /*                                                                            */ | /*                                                                            */ | ||||||
| /* ************************************************************************** */ | /* ************************************************************************** */ | ||||||
|  |  | ||||||
| #include "libftprintf.h" | #include "printf.h" | ||||||
|  |  | ||||||
| void	ft_putstr_fd(char *s, int fd) | void	ft_putstr_fd(char *s, int fd) | ||||||
| { | { | ||||||
|  | |||||||
							
								
								
									
										
											BIN
										
									
								
								ft_putstr_fd.o
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								ft_putstr_fd.o
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| @ -6,11 +6,11 @@ | |||||||
| /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | ||||||
| /*                                                +#+#+#+#+#+   +#+           */ | /*                                                +#+#+#+#+#+   +#+           */ | ||||||
| /*   Created: 2022/09/26 14:44:15 by cchauvet          #+#    #+#             */ | /*   Created: 2022/09/26 14:44:15 by cchauvet          #+#    #+#             */ | ||||||
| /*   Updated: 2022/10/05 20:56:37 by cchauvet         ###   ########.fr       */ | /*   Updated: 2022/10/10 14:42:21 by cchauvet         ###   ########.fr       */ | ||||||
| /*                                                                            */ | /*                                                                            */ | ||||||
| /* ************************************************************************** */ | /* ************************************************************************** */ | ||||||
|  |  | ||||||
| #include "libftprintf.h" | #include "printf.h" | ||||||
|  |  | ||||||
| char	*ft_strchr(const char *s, int c) | char	*ft_strchr(const char *s, int c) | ||||||
| { | { | ||||||
|  | |||||||
							
								
								
									
										
											BIN
										
									
								
								ft_strchr.o
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								ft_strchr.o
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| @ -6,17 +6,19 @@ | |||||||
| /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | ||||||
| /*                                                +#+#+#+#+#+   +#+           */ | /*                                                +#+#+#+#+#+   +#+           */ | ||||||
| /*   Created: 2022/09/27 16:00:49 by cchauvet          #+#    #+#             */ | /*   Created: 2022/09/27 16:00:49 by cchauvet          #+#    #+#             */ | ||||||
| /*   Updated: 2022/10/06 16:53:02 by cchauvet         ###   ########.fr       */ | /*   Updated: 2022/10/10 18:48:37 by cchauvet         ###   ########.fr       */ | ||||||
| /*                                                                            */ | /*                                                                            */ | ||||||
| /* ************************************************************************** */ | /* ************************************************************************** */ | ||||||
|  |  | ||||||
| #include "libftprintf.h" | #include "printf.h" | ||||||
|  |  | ||||||
| char	*ft_strdup(char *s) | char	*ft_strdup(const char *s) | ||||||
| { | { | ||||||
| 	char	*out; | 	char	*out; | ||||||
| 	size_t	i; | 	size_t	i; | ||||||
|  |  | ||||||
|  | 	if (s == NULL) | ||||||
|  | 		return (NULL); | ||||||
| 	out = malloc((ft_strlen(s) + 1) * sizeof(char)); | 	out = malloc((ft_strlen(s) + 1) * sizeof(char)); | ||||||
| 	if (out == NULL) | 	if (out == NULL) | ||||||
| 		return (NULL); | 		return (NULL); | ||||||
|  | |||||||
							
								
								
									
										
											BIN
										
									
								
								ft_strdup.o
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								ft_strdup.o
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										38
									
								
								ft_strjoin.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								ft_strjoin.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,38 @@ | |||||||
|  | /* ************************************************************************** */ | ||||||
|  | /*                                                                            */ | ||||||
|  | /*                                                        :::      ::::::::   */ | ||||||
|  | /*   ft_strjoin.c                                       :+:      :+:    :+:   */ | ||||||
|  | /*                                                    +:+ +:+         +:+     */ | ||||||
|  | /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | ||||||
|  | /*                                                +#+#+#+#+#+   +#+           */ | ||||||
|  | /*   Created: 2022/09/29 11:20:27 by cchauvet          #+#    #+#             */ | ||||||
|  | /*   Updated: 2022/10/10 14:42:41 by cchauvet         ###   ########.fr       */ | ||||||
|  | /*                                                                            */ | ||||||
|  | /* ************************************************************************** */ | ||||||
|  |  | ||||||
|  | #include "printf.h" | ||||||
|  |  | ||||||
|  | char	*ft_strjoin(char *s1, char *s2) | ||||||
|  | { | ||||||
|  | 	size_t	i; | ||||||
|  | 	size_t	j; | ||||||
|  | 	char	*out; | ||||||
|  |  | ||||||
|  | 	if (s1 == NULL || s2 == NULL) | ||||||
|  | 		return (NULL); | ||||||
|  | 	out = malloc((ft_strlen(s1) + ft_strlen(s2) + 1) * sizeof(char)); | ||||||
|  | 	i = 0; | ||||||
|  | 	while (s1[i] != 0) | ||||||
|  | 	{ | ||||||
|  | 		out[i] = s1[i]; | ||||||
|  | 		i++; | ||||||
|  | 	} | ||||||
|  | 	j = 0; | ||||||
|  | 	while (s2[j] != 0) | ||||||
|  | 	{ | ||||||
|  | 		out[i + j] = s2[j]; | ||||||
|  | 		j++; | ||||||
|  | 	} | ||||||
|  | 	out[i + j] = 0; | ||||||
|  | 	return (out); | ||||||
|  | } | ||||||
							
								
								
									
										
											BIN
										
									
								
								ft_strjoin.o
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								ft_strjoin.o
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| @ -6,16 +6,18 @@ | |||||||
| /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | ||||||
| /*                                                +#+#+#+#+#+   +#+           */ | /*                                                +#+#+#+#+#+   +#+           */ | ||||||
| /*   Created: 2022/10/06 17:39:05 by cchauvet          #+#    #+#             */ | /*   Created: 2022/10/06 17:39:05 by cchauvet          #+#    #+#             */ | ||||||
| /*   Updated: 2022/10/06 17:40:41 by cchauvet         ###   ########.fr       */ | /*   Updated: 2022/10/10 15:43:27 by cchauvet         ###   ########.fr       */ | ||||||
| /*                                                                            */ | /*                                                                            */ | ||||||
| /* ************************************************************************** */ | /* ************************************************************************** */ | ||||||
|  |  | ||||||
| #include "libftprintf.h" | #include "printf.h" | ||||||
|  |  | ||||||
| size_t	ft_strlen(const char *s) | size_t	ft_strlen(const char *s) | ||||||
| { | { | ||||||
| 	size_t	i; | 	size_t	i; | ||||||
|  |  | ||||||
|  | 	if (s == NULL) | ||||||
|  | 		return (0); | ||||||
| 	i = 0; | 	i = 0; | ||||||
| 	while (s[i]) | 	while (s[i]) | ||||||
| 		i++; | 		i++; | ||||||
|  | |||||||
							
								
								
									
										
											BIN
										
									
								
								ft_strlen.o
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								ft_strlen.o
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										84
									
								
								ft_ultoabase.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										84
									
								
								ft_ultoabase.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,84 @@ | |||||||
|  | /* ************************************************************************** */ | ||||||
|  | /*                                                                            */ | ||||||
|  | /*                                                        :::      ::::::::   */ | ||||||
|  | /*   ft_ultoabase.c                                     :+:      :+:    :+:   */ | ||||||
|  | /*                                                    +:+ +:+         +:+     */ | ||||||
|  | /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | ||||||
|  | /*                                                +#+#+#+#+#+   +#+           */ | ||||||
|  | /*   Created: 2022/09/29 13:49:45 by cchauvet          #+#    #+#             */ | ||||||
|  | /*   Updated: 2022/10/10 14:45:46 by cchauvet         ###   ########.fr       */ | ||||||
|  | /*                                                                            */ | ||||||
|  | /* ************************************************************************** */ | ||||||
|  |  | ||||||
|  | #include "printf.h" | ||||||
|  |  | ||||||
|  | static size_t	ft_str_size(unsigned long n, size_t base_size) | ||||||
|  | { | ||||||
|  | 	size_t			size; | ||||||
|  |  | ||||||
|  | 	size = 1; | ||||||
|  | 	if (n == 0) | ||||||
|  | 		return (2); | ||||||
|  | 	while (n != 0) | ||||||
|  | 	{ | ||||||
|  | 		n = n / base_size; | ||||||
|  | 		size++; | ||||||
|  | 	} | ||||||
|  | 	return (size); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | static int	ft_isdup(char *str) | ||||||
|  | { | ||||||
|  | 	char	c; | ||||||
|  | 	size_t	i; | ||||||
|  |  | ||||||
|  | 	while (*str != 0) | ||||||
|  | 	{ | ||||||
|  | 		c = *str; | ||||||
|  | 		i = 1; | ||||||
|  | 		while (str[i] != 0) | ||||||
|  | 		{ | ||||||
|  | 			if (str[i] == c) | ||||||
|  | 				return (1); | ||||||
|  | 			i++; | ||||||
|  | 		} | ||||||
|  | 		str++; | ||||||
|  | 	} | ||||||
|  | 	return (0); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | static size_t	ft_base_size(char *base) | ||||||
|  | { | ||||||
|  | 	size_t	len; | ||||||
|  |  | ||||||
|  | 	if (ft_isdup(base)) | ||||||
|  | 		return (0); | ||||||
|  | 	len = ft_strlen(base); | ||||||
|  | 	if (len < 2) | ||||||
|  | 		return (0); | ||||||
|  | 	return (len); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | char	*ft_ultoabase(unsigned long n, char *base) | ||||||
|  | { | ||||||
|  | 	size_t			base_size; | ||||||
|  | 	size_t			str_size; | ||||||
|  | 	char			*out; | ||||||
|  |  | ||||||
|  | 	if (base == NULL) | ||||||
|  | 		return (NULL); | ||||||
|  | 	base_size = ft_base_size(base); | ||||||
|  | 	if (base_size == 0) | ||||||
|  | 		return (NULL); | ||||||
|  | 	str_size = ft_str_size(n, base_size); | ||||||
|  | 	out = malloc(str_size * sizeof(char *)); | ||||||
|  | 	if (out == NULL) | ||||||
|  | 		return (NULL); | ||||||
|  | 	out[--str_size] = 0; | ||||||
|  | 	while (0 < str_size) | ||||||
|  | 	{ | ||||||
|  | 		out[--str_size] = base[n % base_size]; | ||||||
|  | 		n = n / base_size; | ||||||
|  | 	} | ||||||
|  | 	return (out); | ||||||
|  | } | ||||||
							
								
								
									
										
											BIN
										
									
								
								ft_ultoabase.o
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								ft_ultoabase.o
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| @ -6,18 +6,21 @@ | |||||||
| /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | ||||||
| /*                                                +#+#+#+#+#+   +#+           */ | /*                                                +#+#+#+#+#+   +#+           */ | ||||||
| /*   Created: 2022/10/06 16:39:25 by cchauvet          #+#    #+#             */ | /*   Created: 2022/10/06 16:39:25 by cchauvet          #+#    #+#             */ | ||||||
| /*   Updated: 2022/10/07 01:38:18 by cchauvet         ###   ########.fr       */ | /*   Updated: 2022/10/10 19:12:04 by cchauvet         ###   ########.fr       */ | ||||||
| /*                                                                            */ | /*                                                                            */ | ||||||
| /* ************************************************************************** */ | /* ************************************************************************** */ | ||||||
|  |  | ||||||
| #include "libftprintf.h" | #include "printf.h" | ||||||
|  |  | ||||||
| char	*ft_vdprintf(int fd, const char *format, va_list va) | int	ft_vdprintf(int fd, const char *format, va_list va) | ||||||
| { | { | ||||||
| 	char	*str; | 	char	*str; | ||||||
|  | 	int		rv; | ||||||
|  |  | ||||||
| 	str = ft_strdup(""); | 	str = ft_strdup(""); | ||||||
| 	str = ft_vsprintf(str, format, va); | 	str = ft_vsprintf(str, format, va); | ||||||
|  | 	rv = ft_strlen(str); | ||||||
| 	ft_putstr_fd(str, fd); | 	ft_putstr_fd(str, fd); | ||||||
| 	return (str); | 	free(str); | ||||||
|  | 	return (rv); | ||||||
| } | } | ||||||
|  | |||||||
							
								
								
									
										
											BIN
										
									
								
								ft_vdprintf.o
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								ft_vdprintf.o
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| @ -6,13 +6,13 @@ | |||||||
| /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | ||||||
| /*                                                +#+#+#+#+#+   +#+           */ | /*                                                +#+#+#+#+#+   +#+           */ | ||||||
| /*   Created: 2022/10/07 01:05:23 by cchauvet          #+#    #+#             */ | /*   Created: 2022/10/07 01:05:23 by cchauvet          #+#    #+#             */ | ||||||
| /*   Updated: 2022/10/07 01:43:58 by cchauvet         ###   ########.fr       */ | /*   Updated: 2022/10/10 18:12:44 by cchauvet         ###   ########.fr       */ | ||||||
| /*                                                                            */ | /*                                                                            */ | ||||||
| /* ************************************************************************** */ | /* ************************************************************************** */ | ||||||
|  |  | ||||||
| #include "libftprintf.h" | #include "printf.h" | ||||||
|  |  | ||||||
| int	ft_vprintf(const char *format, va_list va) | int	ft_vprintf(const char *format, va_list va) | ||||||
| { | { | ||||||
| 	return (ft_strlen(ft_vdprintf(1, format, va))); | 	return (ft_vdprintf(1, format, va)); | ||||||
| } | } | ||||||
|  | |||||||
							
								
								
									
										
											BIN
										
									
								
								ft_vprintf.o
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								ft_vprintf.o
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										122
									
								
								ft_vsprintf.c
									
									
									
									
									
								
							
							
						
						
									
										122
									
								
								ft_vsprintf.c
									
									
									
									
									
								
							| @ -6,14 +6,53 @@ | |||||||
| /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | ||||||
| /*                                                +#+#+#+#+#+   +#+           */ | /*                                                +#+#+#+#+#+   +#+           */ | ||||||
| /*   Created: 2022/10/06 10:44:36 by cchauvet          #+#    #+#             */ | /*   Created: 2022/10/06 10:44:36 by cchauvet          #+#    #+#             */ | ||||||
| /*   Updated: 2022/10/07 02:26:50 by cchauvet         ###   ########.fr       */ | /*   Updated: 2022/10/10 19:32:04 by cchauvet         ###   ########.fr       */ | ||||||
| /*                                                                            */ | /*                                                                            */ | ||||||
| /* ************************************************************************** */ | /* ************************************************************************** */ | ||||||
|  |  | ||||||
| #include "libftprintf.h" | #include "printf.h" | ||||||
|  |  | ||||||
|  | static size_t	ft_seglen(const char *str) | ||||||
|  | { | ||||||
|  | 	size_t	i; | ||||||
|  |  | ||||||
|  | 	i = 0; | ||||||
|  | 	while ((str[i] != 0 && str[i] != '%') || (str[i] == '%' && i == 0)) | ||||||
|  | 		i++; | ||||||
|  | 	return (i); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | static char	*ft_strfjoin(char *s1, char *s2) | ||||||
|  | { | ||||||
|  | 	size_t	i; | ||||||
|  | 	size_t	j; | ||||||
|  | 	char	*out; | ||||||
|  |  | ||||||
|  | 	out = malloc((ft_strlen(s1) + ft_seglen(s2) + 1) * sizeof(char)); | ||||||
|  | 	if (out == NULL) | ||||||
|  | 		return (NULL); | ||||||
|  | 	i = 0; | ||||||
|  | 	while (s1[i] != 0) | ||||||
|  | 	{ | ||||||
|  | 		out[i] = s1[i]; | ||||||
|  | 		i++; | ||||||
|  | 	} | ||||||
|  | 	free(s1); | ||||||
|  | 	j = 0; | ||||||
|  | 	while ((s2[j] != 0 && s2[j] != '%') || (s2[j] == '%' && j == 0)) | ||||||
|  | 	{ | ||||||
|  | 		out[i + j] = s2[j]; | ||||||
|  | 		j++; | ||||||
|  | 	} | ||||||
|  | 	free(s2); | ||||||
|  | 	out[i + j] = 0; | ||||||
|  | 	return (out); | ||||||
|  | } | ||||||
|  |  | ||||||
| static char	*ft_argtoa(int c, va_list args) | static char	*ft_argtoa(int c, va_list args) | ||||||
| { | { | ||||||
|  | 	char	*out; | ||||||
|  |  | ||||||
| 	if (c == 'c') | 	if (c == 'c') | ||||||
| 		return (ft_ctoa(va_arg(args, int))); | 		return (ft_ctoa(va_arg(args, int))); | ||||||
| 	if (c == 's') | 	if (c == 's') | ||||||
| @ -23,69 +62,44 @@ static char	*ft_argtoa(int c, va_list args) | |||||||
| 	if (c == 'p') | 	if (c == 'p') | ||||||
| 		return (ft_ptoa(va_arg(args, void *))); | 		return (ft_ptoa(va_arg(args, void *))); | ||||||
| 	if (c == 'x') | 	if (c == 'x') | ||||||
| 		return (ft_itoabase(va_arg(args, long int), "0123456789abcdef")); | 		return (ft_ltoabase(va_arg(args, long int), "0123456789abcdef")); | ||||||
| 	if (c == 'X') | 	if (c == 'X') | ||||||
| 		return (ft_itoabase(va_arg(args, long int), "0123456789ABCDEF")); | 		return (ft_ltoabase(va_arg(args, long int), "0123456789ABCDEF")); | ||||||
|  | 	if (c == 'u') | ||||||
|  | 		return (ft_ultoabase(va_arg(args, unsigned long int), "0123456789")); | ||||||
| 	if (c == '%') | 	if (c == '%') | ||||||
| 		return (ft_ctoa('%')); | 		return (ft_strdup("%")); | ||||||
| 	return (NULL); | 	out = ft_strdup("% "); | ||||||
| } | 	if (out == NULL) | ||||||
|  |  | ||||||
| static size_t	ft_seglen(const char *str) |  | ||||||
| { |  | ||||||
| 	size_t	i; |  | ||||||
|  |  | ||||||
| 	i = 0; |  | ||||||
| 	while (str[i] != 0 && str[i] != '%') |  | ||||||
| 		i++; |  | ||||||
| 	return (i); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| static char	*ft_strfjoin(char *s1, const char *s2) |  | ||||||
| { |  | ||||||
| 	size_t	i; |  | ||||||
| 	size_t	j; |  | ||||||
| 	char	*out; |  | ||||||
|  |  | ||||||
| 	if (s1 == NULL || s2 == NULL) |  | ||||||
| 		return (NULL); | 		return (NULL); | ||||||
| 	out = malloc((ft_seglen(s1) + ft_seglen(s2) + 1) * sizeof(char)); | 	out[1] = c; | ||||||
| 	i = 0; |  | ||||||
| 	while (s1[i] != 0 && s2[i] != '%') |  | ||||||
| 	{ |  | ||||||
| 		out[i] = s1[i]; |  | ||||||
| 		i++; |  | ||||||
| 	} |  | ||||||
| 	free(s1); |  | ||||||
| 	j = 0; |  | ||||||
| 	while (s2[j] != 0 && s2[j] != '%') |  | ||||||
| 	{ |  | ||||||
| 		out[i + j] = s2[j]; |  | ||||||
| 		j++; |  | ||||||
| 	} |  | ||||||
| 	out[i + j] = 0; |  | ||||||
| 	return (out); | 	return (out); | ||||||
| } | } | ||||||
|  |  | ||||||
| char	*ft_vsprintf(char *str, const char *format, va_list va) | char	*ft_vsprintf(char *str, const char *format, va_list va) | ||||||
| { | { | ||||||
| 	char		*mid_out; | 	char	*cformat; | ||||||
|  | 	char	*ccformat; | ||||||
|  | 	char	*mid; | ||||||
|  |  | ||||||
| 	while (format != NULL) | 	cformat = ft_strdup(format); | ||||||
|  | 	ccformat = cformat; | ||||||
|  | 	if (str == NULL || cformat == NULL) | ||||||
|  | 		return (0); | ||||||
|  | 	while (cformat != NULL) | ||||||
| 	{ | 	{ | ||||||
| 		str = ft_strfjoin(str, format); | 		if (cformat[0] != '%') | ||||||
| 		format = ft_strchr(format, '%'); | 			str = ft_strfjoin(str, ft_strdup(cformat)); | ||||||
| 		if (format == NULL) | 		cformat = ft_strchr(cformat, '%'); | ||||||
|  | 		if (cformat == NULL) | ||||||
| 			break ; | 			break ; | ||||||
| 		else | 		cformat += 1; | ||||||
| 			format += 1; | 		mid = ft_argtoa(cformat[0], va); | ||||||
| 		mid_out = ft_argtoa(*format, va); | 		while (mid == NULL) | ||||||
| 		if (mid_out == NULL) | 			mid = ft_strdup("(null)"); | ||||||
| 		{ | 		str = ft_strfjoin(str, mid); | ||||||
| 			free(str); | 		cformat += 1; | ||||||
| 			return (0); |  | ||||||
| 		} |  | ||||||
| 		str = ft_strfjoin(str, mid_out); |  | ||||||
| 	} | 	} | ||||||
|  | 	free(ccformat); | ||||||
| 	return (str); | 	return (str); | ||||||
| } | } | ||||||
|  | |||||||
							
								
								
									
										
											BIN
										
									
								
								ft_vsprintf.o
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								ft_vsprintf.o
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								libftprintf.a
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								libftprintf.a
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										10
									
								
								main.c
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								main.c
									
									
									
									
									
								
							| @ -5,16 +5,16 @@ | |||||||
| /*                                                    +:+ +:+         +:+     */ | /*                                                    +:+ +:+         +:+     */ | ||||||
| /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | ||||||
| /*                                                +#+#+#+#+#+   +#+           */ | /*                                                +#+#+#+#+#+   +#+           */ | ||||||
| /*   Created: 2022/10/06 17:35:15 by cchauvet          #+#    #+#             */ | /*   Created: 2022/10/10 17:32:31 by cchauvet          #+#    #+#             */ | ||||||
| /*   Updated: 2022/10/07 02:25:20 by cchauvet         ###   ########.fr       */ | /*   Updated: 2022/10/10 19:29:03 by cchauvet         ###   ########.fr       */ | ||||||
| /*                                                                            */ | /*                                                                            */ | ||||||
| /* ************************************************************************** */ | /* ************************************************************************** */ | ||||||
|  |  | ||||||
| #include "libftprintf.h" | #include "printf.h" | ||||||
| #include <stdio.h> | #include <stdio.h> | ||||||
|  |  | ||||||
| int	main(void) | int	main(void) | ||||||
| { | { | ||||||
| 	ft_printf("%s", "gros peteur"); | 	ft_printf("%% %@ %X\n", 255); | ||||||
| 	return (1); | 	return (0); | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,37 +1,38 @@ | |||||||
| /* ************************************************************************** */ | /* ************************************************************************** */ | ||||||
| /*                                                                            */ | /*                                                                            */ | ||||||
| /*                                                        :::      ::::::::   */ | /*                                                        :::      ::::::::   */ | ||||||
| /*   libftprintf.h                                      :+:      :+:    :+:   */ | /*   printf.h                                           :+:      :+:    :+:   */ | ||||||
| /*                                                    +:+ +:+         +:+     */ | /*                                                    +:+ +:+         +:+     */ | ||||||
| /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | ||||||
| /*                                                +#+#+#+#+#+   +#+           */ | /*                                                +#+#+#+#+#+   +#+           */ | ||||||
| /*   Created: 2022/09/26 14:47:54 by cchauvet          #+#    #+#             */ | /*   Created: 2022/09/26 14:47:54 by cchauvet          #+#    #+#             */ | ||||||
| /*   Updated: 2022/10/07 01:37:57 by cchauvet         ###   ########.fr       */ | /*   Updated: 2022/10/10 19:11:15 by cchauvet         ###   ########.fr       */ | ||||||
| /*                                                                            */ | /*                                                                            */ | ||||||
| /* ************************************************************************** */ | /* ************************************************************************** */ | ||||||
| 
 | 
 | ||||||
| #ifndef LIBFTPRINTF_H | #ifndef PRINTF_H | ||||||
| # define LIBFTPRINTF_H | # define PRINTF_H | ||||||
| # include <stdlib.h> | # include <stdlib.h> | ||||||
| # include <unistd.h> | # include <unistd.h> | ||||||
| # include <stdarg.h> | # include <stdarg.h> | ||||||
| 
 | 
 | ||||||
| char	*ft_strndup(const char *s, size_t n); |  | ||||||
| size_t	ft_strlen(const char *s); | size_t	ft_strlen(const char *s); | ||||||
| char	*ft_strchr(const char *s, int c); | char	*ft_strchr(const char *s, int c); | ||||||
|  | char	*ft_strjoin(char *s1, char *s2); | ||||||
| 
 | 
 | ||||||
| char	*ft_itoa(int n); | char	*ft_itoa(int n); | ||||||
| char	*ft_ctoa(int c); | char	*ft_ctoa(int c); | ||||||
| char	*ft_strdup(char *s); | char	*ft_strdup(const char *s); | ||||||
| char	*ft_ptoa(void *ptr); | char	*ft_ptoa(void *ptr); | ||||||
| char	*ft_utoa(unsigned int n); | char	*ft_utoa(unsigned int n); | ||||||
| char	*ft_itoabase(int n, char *base); | char	*ft_ltoabase(long int n, char *base); | ||||||
|  | char	*ft_ultoabase(long unsigned int n, char *base); | ||||||
| 
 | 
 | ||||||
| int		ft_printf(const char *format, ...); | int		ft_printf(const char *format, ...); | ||||||
| 
 | 
 | ||||||
| int		ft_vprintf(const char *format, va_list va); | int		ft_vprintf(const char *format, va_list va); | ||||||
| char	*ft_vsprintf(char *str, const char *format, va_list va); | char	*ft_vsprintf(char *str, const char *format, va_list va); | ||||||
| char	*ft_vdprintf(int fd, const char *format, va_list va); | int		ft_vdprintf(int fd, const char *format, va_list va); | ||||||
| 
 | 
 | ||||||
| void	ft_putchar_fd(char c, int fd); | void	ft_putchar_fd(char c, int fd); | ||||||
| void	ft_putstr_fd(char *s, int f); | void	ft_putstr_fd(char *s, int f); | ||||||
		Reference in New Issue
	
	Block a user