Exemple #1
0
char		*my_int_to_char(int nb)
{
  char		*res;

  if (nb == 0)
    {
      if ((res = my_xmalloc(2)) == NULL)
	return (NULL);
      res[0] = '0';
      res[1] = '\0';
    }
  else
    {
      if ((res = my_xmalloc(my_int_len(nb) + 2)) == NULL)
	return (NULL);
      my_calc_int_to_char(nb, res, my_int_len(nb));
      res[my_int_len(nb) + 1] = '\0';
    }
  return (res);
}
int		parser(t_box *tab, char *str, int it)
{
  int		i;

  if (it == 1)
    i = 0;
  else if (it == 2)
    i = 1;
  tab->nb[0] = my_getnbr(str);
  str = str + my_int_len(tab->nb[0]);
  tab->sign[0] = str[0];
  str = str + 2;
  while (str[0] != ')')
    {
      tab->nb[i] = my_getnbr(str);
      str = str + my_int_len(tab->nb[i]);
      tab->sign[i] = str[0];
      i = i + 1;
      str = str + 1;
    }
  exec(tab, it);
  return (0);
}
int	get_from_base(int nb, int base)
{
  char	*get;
  int	i;
  int	x;
  int	res;

  i = 0;
  res = 0;
  if ((get = malloc(sizeof(char) * (my_int_len(nb) + 1))) == NULL)
    return (0);
  get = get_int(nb);
  res = 0;
  x = strlen(get) - 1;
  while (get[i])
    {
      res = res + ((get[i] - 48) * puissance(base, x));
      i++;
      x--;
    }
  return (res);
}