All pastes #220797 Raw Edit

Miscellany

public text v1 · immutable
#220797 ·published 2006-10-25 10:17 UTC
rendered paste body
int     my_strlen(char *str);
int     my_power_it(int nb, int power);

char    *DecToBase(char *bf, int nb) // Revoie le decimal dans la base indiquee.
{
  char *rest;
  int   to;
  int   i;

  i = 0;
  to = my_strlen(bf);
  *rest = malloc(nb * my_strlen(bf));
  while (i < (nb * my_strlen(bf)))
    {
      my_putstr("Valeur de i: ");
      my_put_nbr(i);
      my_putchar('\n');
      my_putstr("Valeur de nb: ");
      my_put_nbr(nb);
      my_putchar('\n');
      my_putstr("Valeur de to: ");
      my_put_nbr(to);
      my_putchar('\n');
      my_putstr("Valeur de nb%to: ");
      my_put_nbr(nb%to);
      my_putchar('\n');
      rest[i] = bf[nb % to];
      nb /= to;
      i++;
    }
  rest[i] = '\0';
  my_putstr("Valeur finale de rest: ");
  my_putstr(rest);
  my_putchar('\n');
  return (rest);
}

int     main(int argc, char **argv)
{
  //  char      *osef;
  //*osef = malloc(19);

  if (argc > 1)
    DecToBase("0123456789ABCDEF", my_getnbr(argv[1]));
  else
    write(1, "Error", 5);

  //  my_putstr(osef);
}