int put_convert_to_nbase(unsigned int nbr, int base, char b) { unsigned int quo; char *result; int j; j = 0; result = malloc(my_nbrlen(nbr) * 3 + 2); if (result == NULL) return (0); while (nbr > 0) { quo = nbr / base; while (nbr >= base) nbr = nbr - base; if (nbr > 9 && b == 0) nbr = nbr + 7; if (nbr > 9 && b == 1) nbr = nbr + 39; result[j] = nbr + '0'; j++; nbr = quo; } result[j] = '\0'; my_putstr(my_revstr(result)); return (my_strlen(result)); }
int my_printf(char *format, ...) { va_list ap; unsigned int i; unsigned int width; va_start(ap, format); i = 0; width = 0; while (format[i] != '\0') { if (format[i] != '%') my_putchar(format[i]); else { i = i + 1; while (format[i] == ' ') i = i + 1; if (format[i] >= '0' && format[i] <= '9') { width = find_width(format, i); i = i + my_nbrlen(width); } if (format[i] == '%') my_putchar(format[i]); else find_fmt(ap, format, i, width); } i = i + 1; } va_end(ap); return (0); }
char *format_d(va_list *arg, char *buf, t_opt *opt) { int i; int pad; i = va_arg(*arg, int); if (opt->pre == 0 && i == 0) return (buf); pad = my_nbrlen(i); if (i == 0) pad++; if (i < 0) { i = -i; buf = add_char(buf, '-'); } while (opt->pre != -1 && pad < opt->pre) { buf = add_char(buf, '0'); pad++; } buf = my_put_nbr(i, buf); return (buf); }