| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- /* ************************************************************************** */
- /* */
- /* ::: :::::::: */
- /* ft_putnbr.c :+: :+: :+: */
- /* +:+ +:+ +:+ */
- /* By: bchanot <bchanot@students.42.fr> +#+ +:+ +#+ */
- /* +#+#+#+#+#+ +#+ */
- /* Created: 2016/03/03 02:08:12 by bchanot #+# #+# */
- /* Updated: 2017/04/15 00:41:32 by bchanot ### ########.fr */
- /* */
- /* ************************************************************************** */
- #include "libftprintf.h"
- #include <stdlib.h>
- int pf_puthex(unsigned int n, int fd)
- {
- char *hex;
- hex = NULL;
- if (n >= 16)
- return (pf_puthex(n / 16, fd) + pf_puthex(n % 16, fd));
- else
- {
- hex = ft_strdup("0123456789abcdef");
- ft_putchar_fd(hex[n], fd);
- if (hex)
- free(hex);
- return (1);
- }
- }
- int pf_putoctal(unsigned int n, int fd)
- {
- if (n >= 8)
- return (pf_putoctal(n / 8, fd) + pf_puthex(n % 8, fd));
- else
- {
- ft_putchar_fd(n + 48, fd);
- return (1);
- }
- }
- int pf_puthexm(unsigned int n, int fd)
- {
- char *hex;
- hex = NULL;
- if (n >= 16)
- return (pf_puthexm(n / 16, fd) + pf_puthexm(n % 16, fd));
- else
- {
- hex = ft_strdup("0123456789ABCDEF");
- ft_putchar_fd(hex[n], fd);
- if (hex)
- free(hex);
- return (1);
- }
- }
- int pf_putunbr(unsigned int n, int fd)
- {
- if (n >= 10)
- return (pf_putunbr(n / 10, fd) + pf_putunbr(n % 10, fd));
- ft_putchar_fd(48 + n, fd);
- return (1);
- }
|