diff options
Diffstat (limited to 'c07/ex04/ft_convert_base2.c')
| -rw-r--r-- | c07/ex04/ft_convert_base2.c | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/c07/ex04/ft_convert_base2.c b/c07/ex04/ft_convert_base2.c index e69de29..be9a03e 100644 --- a/c07/ex04/ft_convert_base2.c +++ b/c07/ex04/ft_convert_base2.c @@ -0,0 +1,69 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_convert_base2.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/10 20:22:09 by cacharle #+# #+# */ +/* Updated: 2019/07/11 10:10:08 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int check_base(char *base) +{ + int i; + int j; + + i = 0; + while (base[i]) + { + if (base[i] == '-' || base[i] == '+' || base[i] == ' ' + || base[i] == '\t' || base[i] == '\n' || base[i] == '\v' + || base[i] == '\f' || base[i] == '\r') + return (0); + j = 0; + while (base[j]) + { + if (j != i && base[j] == base[i]) + return (0); + j++; + } + i++; + } + if (i < 2) + return (0); + return (1); +} + +int ft_pow(int base, int exponent) +{ + int accumulator; + + accumulator = 1; + while (exponent-- > 0) + accumulator *= base; + return (accumulator); +} + +int position_in_base(char digit, char *base) +{ + int i; + + i = 0; + while (digit != base[i] && base[i]) + i++; + if (base[i] == '\0') + return (-1); + return (i); +} + +int some_strlen(char *str) +{ + int counter; + + counter = 0; + while (str[counter]) + counter++; + return (counter); +} |
