diff --git a/C_08/git/ex02/ft_abs.h b/C_08/git/ex02/ft_abs.h new file mode 100644 index 0000000..e7adcfe --- /dev/null +++ b/C_08/git/ex02/ft_abs.h @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_boolean.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gbaconni +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/08/20 10:17:09 by gbaconni #+# #+# */ +/* Updated: 2021/08/20 12:05:50 by gbaconni ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_ABS_H +# define FT_ABS_H + +# define ABS(Value) ((Value < 0)? (-Value): (Value)) + +#endif diff --git a/C_08/git/ex02/main.c b/C_08/git/ex02/main.c new file mode 100644 index 0000000..c609c73 --- /dev/null +++ b/C_08/git/ex02/main.c @@ -0,0 +1,50 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gbaconni +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/08/20 10:26:50 by gbaconni #+# #+# */ +/* Updated: 2021/08/20 10:34:14 by gbaconni ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_abs.h" +#include + +static int ft_atoi(char *str) +{ + int nb; + int s; + int i; + + nb = 0; + s = 1; + i = 0; + while (str[i] != '\0' && (str[i] == ' ' || (str[i] >= '\t' && str[i] <= '\r'))) + i++; + while (str[i] != '\0') + { + if (str[i] == '+') + s += 0; + else if (str[i] == '-') + s *= -1; + else if (str[i] >= '0' && str[i] <= '9') + nb = nb * 10 + str[i] - '0'; + else + break ; + i++; + } + return (nb * s); +} + +int main(int argc, char *argv[]) +{ + int n; + + (void) argc; + n = ft_atoi(argv[1]); + printf("%d\n", ABS(n)); + return (0); +} diff --git a/C_08/git/ex02/main.sh b/C_08/git/ex02/main.sh new file mode 100755 index 0000000..109663b --- /dev/null +++ b/C_08/git/ex02/main.sh @@ -0,0 +1,9 @@ +#!/bin/sh +set -e +norminette -R CheckDefine *.h +norminette -R CheckForbiddenSourceHeader ft_*.c +cpp main.c +gcc -Wall -Wextra -Werror -o a.out *.c +echo $(basename $PWD): +./a.out "$@" +rm -f a.out