ft_dprintf.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /* ************************************************************************** */
  2. /* */
  3. /* ::: :::::::: */
  4. /* ft_dprintf.c :+: :+: :+: */
  5. /* +:+ +:+ +:+ */
  6. /* By: mazimi <marvin@42.fr> +#+ +:+ +#+ */
  7. /* +#+#+#+#+#+ +#+ */
  8. /* Created: 2016/02/12 17:47:53 by mazimi #+# #+# */
  9. /* Updated: 2016/10/29 19:51:55 by mazimi ### ########.fr */
  10. /* */
  11. /* ************************************************************************** */
  12. #include "../libft.h"
  13. int ft_dprintf(int fd, const char *format, ...)
  14. {
  15. va_list ap;
  16. int i;
  17. va_start(ap, format);
  18. i = 0;
  19. while (format[i])
  20. {
  21. if (format[i] == '%')
  22. {
  23. i++;
  24. if (format[i] == 's')
  25. ft_putstr_fd(va_arg(ap, char*), fd);
  26. else if (format[i] == 'd')
  27. ft_putnbr_fd(va_arg(ap, int), fd);
  28. else if (format[i] == 'c')
  29. ft_putchar_fd(va_arg(ap, int), fd);
  30. i++;
  31. }
  32. while ((format[i] != '%') && (format[i]))
  33. {
  34. ft_putchar_fd(format[i], fd);
  35. i++;
  36. }
  37. }
  38. return (0);
  39. }