diff options
Diffstat (limited to 'exam02/rendu')
| -rwxr-xr-x | exam02/rendu/__GIT_HISTORY | 116 | ||||
| -rwxr-xr-x | exam02/rendu/aff_a/aff_a.c | 21 | ||||
| -rwxr-xr-x | exam02/rendu/ft_atoi/ft_atoi.c | 59 | ||||
| -rwxr-xr-x | exam02/rendu/ft_list_remove_if/ft_list_remove_if.c | 38 | ||||
| -rwxr-xr-x | exam02/rendu/ft_rrange/ft_rrange.c | 47 | ||||
| -rwxr-xr-x | exam02/rendu/ft_strrev/ft_strrev.c | 33 | ||||
| -rwxr-xr-x | exam02/rendu/ft_swap/ft_swap.c | 20 | ||||
| -rwxr-xr-x | exam02/rendu/inter/inter.c | 64 |
8 files changed, 398 insertions, 0 deletions
diff --git a/exam02/rendu/__GIT_HISTORY b/exam02/rendu/__GIT_HISTORY new file mode 100755 index 0000000..d5f359c --- /dev/null +++ b/exam02/rendu/__GIT_HISTORY @@ -0,0 +1,116 @@ +commit 3504df713290070aacf0a8da8001336fb62b4577 +Author: Exam 42 <exam-no-reply@42.fr> +Date: Fri Jul 19 20:46:13 2019 +0200 + + asdfasdf + + ft_list_remove_if/ft_list_remove_if.c | 4 +++- + 1 file changed, 3 insertions(+), 1 deletion(-) + +commit 9d00fa46ce651f5943087bad69a911bfebdc88ad +Author: Exam 42 <exam-no-reply@42.fr> +Date: Fri Jul 19 20:39:22 2019 +0200 + + asf + + ft_list_remove_if/ft_list_remove_if.c | 4 +++- + 1 file changed, 3 insertions(+), 1 deletion(-) + +commit 6d9d9ca53f11377f3e2756fd61aa358be5aabdd2 +Author: Exam 42 <exam-no-reply@42.fr> +Date: Fri Jul 19 20:38:29 2019 +0200 + + asf + + ft_list_remove_if/ft_list_remove_if.c | 5 +---- + 1 file changed, 1 insertion(+), 4 deletions(-) + +commit 2f6ad7d91e28d3179d8fd777fe88579d732f15fb +Author: Exam 42 <exam-no-reply@42.fr> +Date: Fri Jul 19 20:37:13 2019 +0200 + + list + + ft_list_remove_if/ft_list_remove_if.c | 37 +++++++++++++++++++++++++++++++++++ + 1 file changed, 37 insertions(+) + +commit e1d809b40ef3936085f2a56d9e54848b7e77bd8a +Author: Exam 42 <exam-no-reply@42.fr> +Date: Fri Jul 19 20:00:12 2019 +0200 + + asdfasdf + + ft_rrange/ft_rrange.c | 27 ++++++++++----------------- + 1 file changed, 10 insertions(+), 17 deletions(-) + +commit 71bf2a5c30017e01d039a3f114b5cc01f4ad334a +Author: Exam 42 <exam-no-reply@42.fr> +Date: Fri Jul 19 19:09:56 2019 +0200 + + bonjour + + ft_rrange/ft_rrange.c | 9 +++++++-- + 1 file changed, 7 insertions(+), 2 deletions(-) + +commit 40feb08e3202c7d6c83e09b7526258ff82a0a293 +Author: Exam 42 <exam-no-reply@42.fr> +Date: Fri Jul 19 18:54:17 2019 +0200 + + ft_rrange size + + ft_rrange/ft_rrange.c | 18 +++++++++++++++--- + 1 file changed, 15 insertions(+), 3 deletions(-) + +commit 9b8fdc6dcf64a8aaf46bbd39f3598616f32e4fc5 +Author: Exam 42 <exam-no-reply@42.fr> +Date: Fri Jul 19 18:20:30 2019 +0200 + + ft_rrange + + ft_rrange/ft_rrange.c | 37 +++++++++++++++++++++++++++++++++++++ + 1 file changed, 37 insertions(+) + +commit e55263c319f4491638e764f7418655a92facec58 +Author: Exam 42 <exam-no-reply@42.fr> +Date: Fri Jul 19 18:04:12 2019 +0200 + + ft_atoi + + ft_atoi/ft_atoi.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ + 1 file changed, 59 insertions(+) + +commit 6fbc33f57a19fb0b0f101ad538a2011007429568 +Author: Exam 42 <exam-no-reply@42.fr> +Date: Fri Jul 19 17:45:06 2019 +0200 + + inter + + inter/inter.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + 1 file changed, 64 insertions(+) + +commit 766b1b4abec091287378709d8f7e20fd27f020b4 +Author: Exam 42 <exam-no-reply@42.fr> +Date: Fri Jul 19 17:19:23 2019 +0200 + + ft_strrev + + ft_strrev/ft_strrev.c | 33 +++++++++++++++++++++++++++++++++ + 1 file changed, 33 insertions(+) + +commit 06ff02b093ea8da767601aca500c4d7a7ed4db63 +Author: Exam 42 <exam-no-reply@42.fr> +Date: Fri Jul 19 17:07:19 2019 +0200 + + ft_swap + + ft_swap/ft_swap.c | 20 ++++++++++++++++++++ + 1 file changed, 20 insertions(+) + +commit 4b856e7c41ed7373d74bbe1fe349f235c5e54e79 +Author: Exam 42 <exam-no-reply@42.fr> +Date: Fri Jul 19 17:04:35 2019 +0200 + + aff_a + + aff_a/aff_a.c | 21 +++++++++++++++++++++ + 1 file changed, 21 insertions(+) diff --git a/exam02/rendu/aff_a/aff_a.c b/exam02/rendu/aff_a/aff_a.c new file mode 100755 index 0000000..ab4867c --- /dev/null +++ b/exam02/rendu/aff_a/aff_a.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* aff_a.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: exam <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/19 17:01:33 by exam #+# #+# */ +/* Updated: 2019/07/19 17:03:04 by exam ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include <unistd.h> + +int main(int argc, char **argv) +{ + (void)argc; + (void)argv; + write(1, "a\n", 2); + return (0); +} diff --git a/exam02/rendu/ft_atoi/ft_atoi.c b/exam02/rendu/ft_atoi/ft_atoi.c new file mode 100755 index 0000000..eda0f8d --- /dev/null +++ b/exam02/rendu/ft_atoi/ft_atoi.c @@ -0,0 +1,59 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_atoi.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: exam <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/19 17:46:19 by exam #+# #+# */ +/* Updated: 2019/07/19 18:03:23 by exam ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int pow10(int exponent) +{ + int acc; + + acc = 1; + while (exponent > 0) + { + acc *= 10; + exponent--; + } + return (acc); +} + + +int ft_atoi(const char *str) +{ + int nb; + int i; + int j; + int is_negative; + + nb = 0; + while (*str == ' ' | *str == '\t' || *str == '\n' || *str == '\v' + || *str == '\f' || *str == '\r') + str++; + is_negative = 0; + if (*str == '-' || *str == '+') + { + if (*str == '-') + is_negative = 1; + str++; + } + j = 0; + while (str[j] >= '0' && str[j] <= '9') + j++; + j--; + i = 0; + while (j >= 0) + { + nb += (str[j] - '0') * pow10(i); + i++; + j--; + } + if (is_negative) + nb = -nb; + return (nb); +} diff --git a/exam02/rendu/ft_list_remove_if/ft_list_remove_if.c b/exam02/rendu/ft_list_remove_if/ft_list_remove_if.c new file mode 100755 index 0000000..57d627c --- /dev/null +++ b/exam02/rendu/ft_list_remove_if/ft_list_remove_if.c @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_list_remove_if.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: exam <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/19 20:02:01 by exam #+# #+# */ +/* Updated: 2019/07/19 20:46:03 by exam ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_list.h" + +void ft_list_remove_if(t_list **begin_list, void *data_ref, int (*cmp)()) +{ + t_list *cursor; + t_list *prev; + + if (!*begin_list) + return ; + while (*begin_list && (*cmp)(data_ref, (*begin_list)->data)) + *begin_list = (*begin_list)->next; + cursor = *begin_list; + prev = NULL; + while (cursor) + { + while (cursor && (*cmp)(data_ref, cursor->data)) + { + if (prev != NULL) + prev->next = cursor->next; + cursor = cursor->next; + } + prev = cursor; + if (cursor) + cursor = cursor->next; + } +} diff --git a/exam02/rendu/ft_rrange/ft_rrange.c b/exam02/rendu/ft_rrange/ft_rrange.c new file mode 100755 index 0000000..d97081a --- /dev/null +++ b/exam02/rendu/ft_rrange/ft_rrange.c @@ -0,0 +1,47 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_rrange.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: exam <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/19 18:05:29 by exam #+# #+# */ +/* Updated: 2019/07/19 19:59:56 by exam ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include <stdlib.h> + +long unsigned int get_size(int start, int end) +{ + long unsigned int size; + + if (start < end) + size = (long int)end - (long int)start; + else if (start > end) + size = (long int)start - (long int)end; + else + size = 0; + return (size); +} + +int *ft_rrange(int start, int end) +{ + int *rrange; + long unsigned int i; + + if ((rrange = (int*)malloc(sizeof(int) * (get_size(start, end) + 1))) == NULL) + return (NULL); + rrange[0] = end; + if (start == end) + return (rrange); + i = 0; + while (end != start) + { + rrange[i] = end; + end += (end < start ? 1 : -1); + i++; + } + rrange[i] = start; + return (rrange); +} diff --git a/exam02/rendu/ft_strrev/ft_strrev.c b/exam02/rendu/ft_strrev/ft_strrev.c new file mode 100755 index 0000000..c58bc25 --- /dev/null +++ b/exam02/rendu/ft_strrev/ft_strrev.c @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strrev.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: exam <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/19 17:08:38 by exam #+# #+# */ +/* Updated: 2019/07/19 17:18:13 by exam ### ########.fr */ +/* */ +/* ************************************************************************** */ + +char *ft_strrev(char *str) +{ + int i; + int j; + char tmp; + + i = 0; + j = 0; + while (str[j]) + j++; + j--; + while (i < j) + { + tmp = str[i]; + str[i] = str[j]; + str[j] = tmp; + j--; + i++; + } + return (str); +} diff --git a/exam02/rendu/ft_swap/ft_swap.c b/exam02/rendu/ft_swap/ft_swap.c new file mode 100755 index 0000000..acf1212 --- /dev/null +++ b/exam02/rendu/ft_swap/ft_swap.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_swap.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: exam <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/19 17:05:36 by exam #+# #+# */ +/* Updated: 2019/07/19 17:06:14 by exam ### ########.fr */ +/* */ +/* ************************************************************************** */ + +void ft_swap(int *a, int *b) +{ + int tmp; + + tmp = *a; + *a = *b; + *b = tmp; +} diff --git a/exam02/rendu/inter/inter.c b/exam02/rendu/inter/inter.c new file mode 100755 index 0000000..5dc911c --- /dev/null +++ b/exam02/rendu/inter/inter.c @@ -0,0 +1,64 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* inter.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: exam <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/19 17:20:35 by exam #+# #+# */ +/* Updated: 2019/07/19 17:44:03 by exam ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include <unistd.h> + +int already_checked(char *str, int index) +{ + char tested; + + tested = str[index]; + while (index-- > 0) + if (str[index] == tested) + return (1); + return (0); +} + +int inside(char *str, char c) +{ + while (*str) + { + if (c == *str) + return (1); + str++; + } + return (0); +} + +int main(int argc, char **argv) +{ + char *str1; + char *str2; + int i; + + if (argc != 3) + { + write(1, "\n", 1); + return (0); + } + i = 0; + str1 = argv[1]; + str2 = argv[2]; + while (str1[i]) + { + if (already_checked(str1, i)) + { + i++; + continue ; + } + if (inside(str2, str1[i])) + write(1, &str1[i], 1); + i++; + } + write(1, "\n", 1); + return (0); +} |
