int fill_arg(int i, va_list *valist, const char *str) { char c; t_spec_flags opts; ft_bzero(&opts, sizeof(t_spec_flags)); i += fill_flags(str + i + 1, &opts) + 1; i += fill_width(str + i, &opts); i += fill_precision(str + i, &opts); i += fill_lenght(str + i, &opts); if ((c = str[i]) == 'S' || c == 'C' || c == 'D' || c == 'U' || c == 'O') opts.len_mod = LM_L; if (c == 'd' || c == 'i' || c == 'D') print_int(valist, &opts); else if (c == 'u' || c == 'U') print_uint(valist, &opts); else if (c == 's' || c == 'S') print_str(valist, &opts); else if (c == 'c' || c == 'C') print_char(valist, &opts); else if (c == 'p' || c == 'x' || c == 'X') print_hex(valist, &opts, c); else if (c == 'o' || c == 'O') print_octal(valist, &opts); else if (c == '%') ft_putchar(c); return (i); }
int dispvar(char **format, va_list ap) { int wr; t_args *arg; wr = 0; arg = (t_args*)malloc(sizeof(t_args)); *format += 1; if (**format != 0) { init_arg(&arg); while (is_flag(**format)) { check_flags(format, &arg); check_field(format, &arg, ap); check_prec(format, &arg, ap); check_length(format, &arg); } wr += print_char(format, &arg, ap); wr += print_hexa(format, &arg, ap); wr += print_decimal(format, &arg, ap); wr += print_octal(format, &arg, ap); } free(arg); return (wr); }
/*********************************************************** * * The print_octal function takes an integer in decimal form * and prints its octal form. */ void print_octal(int x) { if(x == 8){ printf("%d\n", x); } else{ x = x % 8; print_octal(x); } }
/******************************************************************** * * The main function prompts users for inputs. * It calls print_octal to print its octal form. */ int main() { int x; printf("Enter a number between 0 and 32767:\n"); scanf("%d", &x); //printf("In decimal, your nubmer is: %d",x); printf("In octal, your nubmer is: "); print_octal(x); printf("\n"); return 0; }
unsigned int print_it(t_tmp_arg *tmp, t_params *params, char c, unsigned int chars_to_save) { unsigned int wt; wt = 0; (c == 'd') ? (wt = print_int(tmp, params, 0, 0)) : (0); (c == 'i') ? (wt = print_int(tmp, params, 0, 0)) : (0); (c == 'u') ? (wt = print_uint(tmp, params, 0, 0)) : (0); (c == 'x') ? (wt = print_little_hexa(tmp, params, 0, 0)) : (0); (c == 'X') ? (wt = print_large_hexa(tmp, params, 0, 0)) : (0); (c == 'n') ? (wt = save_chars(tmp, chars_to_save)) : (0); (c == 'o') ? (wt = print_octal(tmp, params, 0, 0)) : (0); (c == 'c') ? (wt = print_char(tmp, params, 0, 0)) : (0); (c == 's') ? (wt = print_str(tmp, params, 0, 0)) : (0); (c == '%') ? (wt = print_percent()) : (0); (c == 'S') ? (wt = print_all_str(tmp, params, 0, 0)) : (0); (c == 'p') ? (wt = print_ptr(tmp, params, 0, 0)) : (0); (c == 'b') ? (wt = print_binary(tmp, params, 0, 0)) : (0); return (wt); }