Browse Source

[enh] libft: ft_(d)printf: handle char, use else if.

Moul 4 years ago
parent
commit
185a274a15
2 changed files with 8 additions and 4 deletions
  1. 4 2
      src/ft_dprintf.c
  2. 4 2
      src/ft_printf.c

+ 4 - 2
src/ft_dprintf.c

@@ -6,7 +6,7 @@
 /*   By: mazimi <marvin@42.fr>                      +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2016/02/12 17:47:53 by mazimi            #+#    #+#             */
-/*   Updated: 2016/02/12 17:48:01 by mazimi           ###   ########.fr       */
+/*   Updated: 2016/10/29 19:51:55 by mazimi           ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -26,8 +26,10 @@ int	ft_dprintf(int fd, const char *format, ...)
 			i++;
 			if (format[i] == 's')
 				ft_putstr_fd(va_arg(ap, char*), fd);
-			if (format[i] == 'd')
+			else if (format[i] == 'd')
 				ft_putnbr_fd(va_arg(ap, int), fd);
+			else if (format[i] == 'c')
+				ft_putchar_fd(va_arg(ap, int), fd);
 			i++;
 		}
 		while ((format[i] != '%') && (format[i]))

+ 4 - 2
src/ft_printf.c

@@ -6,7 +6,7 @@
 /*   By: mazimi <marvin@42.fr>                      +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2016/02/12 17:47:22 by mazimi            #+#    #+#             */
-/*   Updated: 2016/02/12 17:47:41 by mazimi           ###   ########.fr       */
+/*   Updated: 2016/10/29 19:50:04 by mazimi           ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -26,8 +26,10 @@ int	ft_printf(const char *format, ...)
 			i++;
 			if (format[i] == 's')
 				ft_putstr(va_arg(ap, char*));
-			if (format[i] == 'd')
+			else if (format[i] == 'd')
 				ft_putnbr(va_arg(ap, int));
+			else if (format[i] == 'c')
+				ft_putchar(va_arg(ap, int));
 			i++;
 		}
 		while ((format[i] != '%') && (format[i]))