All pastes #199754 Raw Edit

Miscellany

public text v1 · immutable
#199754 ·published 2006-10-12 18:49 UTC
rendered paste body
int     find_pos(char c, char *s);
int     my_power(int x, int n);


int     my_get_nbr_base(char *n, char *base)
{
  int   i;
  int   res;

  i = 0;
  res = 0;
  while(n[i] != '\0')
    {
      res = res + find_pos(n[i], base) * my_power(my_strlen(base), my_strlen(n) - i - 1);
      i++;
    }
  return (res);
}


int     find_pos(char c, char *s)
{
  int   i;

  i = 0;
  while (s[i] != '\0')
    {
      if (s[i] == c)
        return (i);
      i++;
    }
  return (-1);
}


int     my_power(int x, int n)
{
  if (n == 0)
    return (1);
  if (n < 0)
    return (0);
  return (x * my_power(x, n - 1));
}