int fcheck(int fd, va_list p, t_form formats[], char f) { int j; int i; int ok; ok = 0; i = 0; j = 0; while (formats[i].c != 0) { if (formats[i].c == f) { j += formats[i].f(fd, p); ok = 1; } i++; } if (ok == 0) { my_fputchar(fd, '%'); my_fputchar(fd, f); j += 2; } return (j); }
void my_fprintf(int fd, const char *format, ...) { va_list ap; int i; i = 0; va_start(ap, format); while (format[i]) { while (format[i] && format[i] != '%') my_fputchar(fd, format[i++]); if (format[i] == '%') { check_option(fd, format[++i], ap); i++; } } va_end(ap); }
int my_fprintf(int fd, const char *format, ...) { va_list ap; int i; i = 0; va_start(ap, format); while (*format) { if (*format == '%') { i += fcorr(fd, ap, *(format + 1)); format++; } else { my_fputchar(fd, *format); i++; } format++; } return (i); }
void my_fputnbr(int fd, int nb) { if (nb / 10 > 0) my_fputnbr(fd, nb / 10); my_fputchar(fd, nb % 10 + 48); }