pf_putnbrlong.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* ************************************************************************** */
  2. /* */
  3. /* ::: :::::::: */
  4. /* pf_putnbrlong.c :+: :+: :+: */
  5. /* +:+ +:+ +:+ */
  6. /* By: bchanot <bchanot@students.42.fr> +#+ +:+ +#+ */
  7. /* +#+#+#+#+#+ +#+ */
  8. /* Created: 2016/03/13 16:21:57 by bchanot #+# #+# */
  9. /* Updated: 2016/04/12 02:10:56 by bchanot ### ########.fr */
  10. /* */
  11. /* ************************************************************************** */
  12. #include "libftprintf.h"
  13. #include <stdlib.h>
  14. int pf_putuhex(long long unsigned int n, int fd)
  15. {
  16. char *hex;
  17. hex = NULL;
  18. if (n >= 16)
  19. return (pf_putuhex(n / 16, fd) + pf_putuhex(n % 16, fd));
  20. else
  21. {
  22. hex = ft_strdup("0123456789abcdef");
  23. ft_putchar_fd(hex[n], fd);
  24. free(hex);
  25. return (1);
  26. }
  27. }
  28. int pf_putuoctal(long long unsigned int n, int fd)
  29. {
  30. if (n >= 8)
  31. return (pf_putuoctal(n / 8, fd) + pf_putuhex(n % 8, fd));
  32. else
  33. {
  34. ft_putchar_fd(n + 48, fd);
  35. return (1);
  36. }
  37. }
  38. int pf_putuhexm(long long unsigned int n, int fd)
  39. {
  40. char *hex;
  41. hex = NULL;
  42. if (n >= 16)
  43. return (pf_putuhexm(n / 16, fd) + pf_putuhexm(n % 16, fd));
  44. else
  45. {
  46. hex = ft_strdup("0123456789ABCDEF");
  47. ft_putchar_fd(hex[n], fd);
  48. free(hex);
  49. return (1);
  50. }
  51. }
  52. int pf_putunbrlong(long long unsigned int n, int fd)
  53. {
  54. if (n >= 10)
  55. return (pf_putunbrlong(n / 10, fd) + pf_putunbrlong(n % 10, fd));
  56. ft_putchar_fd(48 + n, fd);
  57. return (1);
  58. }