diff --git a/C_Piscine_C_07/git/ex01/ft_range.c b/C_Piscine_C_07/git/ex01/ft_range.c index ce45f48..d0ed773 100644 --- a/C_Piscine_C_07/git/ex01/ft_range.c +++ b/C_Piscine_C_07/git/ex01/ft_range.c @@ -11,7 +11,6 @@ /* ************************************************************************** */ #include -#include int *ft_range(int min, int max) { @@ -20,10 +19,10 @@ int *ft_range(int min, int max) int i; if (min < max) - size = max - min; + size = (max - min) + 1; else return (NULL); - range = (int *) malloc(size * sizeof(char)); + range = (int *) malloc(size * sizeof(int)); i = 0; while (i < size) { diff --git a/C_Piscine_C_07/git/ex01/main.c b/C_Piscine_C_07/git/ex01/main.c index b3f5e8d..45547ca 100644 --- a/C_Piscine_C_07/git/ex01/main.c +++ b/C_Piscine_C_07/git/ex01/main.c @@ -32,10 +32,9 @@ int main(void) printf("Input Max: "); scanf("%d", &max); result = ft_range(min, max); - size = 0; - while (result[size++]) - continue ; printf("min=%d max=%d (ft_range)\nresult:\n", min, max); + size = (max - min) + 1; + printf("size=%d\n", size); i = 0; while (i < size) { diff --git a/C_Piscine_C_07/git/ex02/.ft_ultimate_range.c.swp b/C_Piscine_C_07/git/ex02/.ft_ultimate_range.c.swp new file mode 100644 index 0000000..d0b4030 Binary files /dev/null and b/C_Piscine_C_07/git/ex02/.ft_ultimate_range.c.swp differ diff --git a/C_Piscine_C_07/git/ex02/ft_ultimate_range.c b/C_Piscine_C_07/git/ex02/ft_ultimate_range.c new file mode 100644 index 0000000..84ad968 --- /dev/null +++ b/C_Piscine_C_07/git/ex02/ft_ultimate_range.c @@ -0,0 +1,39 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_ultimate_range.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gbaconni +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/08/18 18:13:35 by gbaconni #+# #+# */ +/* Updated: 2021/08/18 18:32:22 by gbaconni ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +int ft_ultimate_range(int **range, int min, int max) +{ + int *r; + int size; + int i; + + (void) range; + if (min < max) + size = (max - min) - 1; + else + { + r = NULL; + range = &r; + return (0); + } + r = (int *) malloc(size * sizeof(int)); + i = 0; + while (i < size) + { + r[i] = min + i + 1; + i++; + } + range = &r; + return (size); +} diff --git a/C_Piscine_C_07/git/ex02/main.c b/C_Piscine_C_07/git/ex02/main.c new file mode 100644 index 0000000..582dc59 --- /dev/null +++ b/C_Piscine_C_07/git/ex02/main.c @@ -0,0 +1,44 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gbaconni +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/08/18 18:11:09 by gbaconni #+# #+# */ +/* Updated: 2021/08/18 18:31:33 by gbaconni ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include +#include + +int ft_ultimate_range(int **range, int min, int max); + +int main(void) +{ + int i; + int min; + int max; + int size; + int *range; + + min = 0; + max = 0; + size = 0; + printf("Input Min: "); + scanf("%d", &min); + printf("Input Max: "); + scanf("%d", &max); + size = ft_ultimate_range(&range, min, max); + printf("size=%d min=%d max=%d (ft_ultimate_range)\nrange:\n", size, min, max); + i = 0; + while (i < size) + { + printf("range[%d] = %d\n", i, range[i]); + i++; + } + return (0); +} diff --git a/C_Piscine_C_07/git/ex02/main.sh b/C_Piscine_C_07/git/ex02/main.sh new file mode 100755 index 0000000..292faee --- /dev/null +++ b/C_Piscine_C_07/git/ex02/main.sh @@ -0,0 +1,8 @@ +#!/bin/sh +set -e +#norminette -R CheckForbiddenSourceHeader ft_*.c +norminette -R CheckForbiddenSourceHeader +gcc -Wall -Wextra -Werror -o a.out *.c +echo $(basename $PWD): +./a.out +rm -f a.out diff --git a/C_Piscine_C_08/Makefile b/C_Piscine_C_08/Makefile new file mode 100644 index 0000000..540f66a --- /dev/null +++ b/C_Piscine_C_08/Makefile @@ -0,0 +1,23 @@ + +# +# Copyright (c) 2021 Guy Baconniere. +# +## How to use this Makefile +# +# cd git +# mkdir ex00 +# cd ex00 +# make -f ../../Makefile ex00 +# + +clone: + @git clone git@vogsphere.42lausanne.ch:vogsphere/intra-uuid-dc28ac79-9ee2-482c-b047-2b9717fad174-3732452 git + +cc: + @norminette -R CheckForbiddenSourceHeader + @gcc -Wall -Wextra -Werror -o a.out *.c + @./a.out + @rm -f a.out + +all: clone + diff --git a/C_Piscine_C_08/fr.subject.pdf b/C_Piscine_C_08/fr.subject.pdf new file mode 100644 index 0000000..745cf85 Binary files /dev/null and b/C_Piscine_C_08/fr.subject.pdf differ