diff options
| author | Charles <sircharlesaze@gmail.com> | 2019-07-26 23:17:36 +0200 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2019-07-26 23:17:36 +0200 |
| commit | 8ec5431354bdb582455e8c32758098c5a0fdada2 (patch) | |
| tree | 480c68814f822439850029df0e0249a2cafb8177 /exam_final/rendu | |
| parent | 475449dd4b1f3308bac6f72c34d87812216a0738 (diff) | |
| download | piscine-8ec5431354bdb582455e8c32758098c5a0fdada2.tar.gz piscine-8ec5431354bdb582455e8c32758098c5a0fdada2.tar.bz2 piscine-8ec5431354bdb582455e8c32758098c5a0fdada2.zip | |
exam final
Diffstat (limited to 'exam_final/rendu')
| -rwxr-xr-x | exam_final/rendu/__GIT_HISTORY | 122 | ||||
| -rwxr-xr-x | exam_final/rendu/aff_last_param/aff_last_param.c | 31 | ||||
| -rwxr-xr-x | exam_final/rendu/aff_z/aff_z.c | 21 | ||||
| -rwxr-xr-x | exam_final/rendu/brainfuck/brainfuck.c | 85 | ||||
| -rwxr-xr-x | exam_final/rendu/brainfuck/stack.c | 42 | ||||
| -rwxr-xr-x | exam_final/rendu/brainfuck/stack.h | 26 | ||||
| -rwxr-xr-x | exam_final/rendu/count_alpha/count_alpha.c | 109 | ||||
| -rwxr-xr-x | exam_final/rendu/ft_atoi/ft_atoi.c | 38 | ||||
| -rwxr-xr-x | exam_final/rendu/ft_itoa/ft_itoa.c | 64 | ||||
| -rwxr-xr-x | exam_final/rendu/ft_putstr/ft_putstr.c | 19 | ||||
| -rwxr-xr-x | exam_final/rendu/ft_split/ft_split.c | 74 | ||||
| -rwxr-xr-x | exam_final/rendu/ft_strrev/ft_strrev.c | 40 | ||||
| -rwxr-xr-x | exam_final/rendu/last_word/last_word.c | 50 | ||||
| -rwxr-xr-x | exam_final/rendu/ord_alphlong/helper.c | 52 | ||||
| -rwxr-xr-x | exam_final/rendu/ord_alphlong/helper2.c | 77 | ||||
| -rwxr-xr-x | exam_final/rendu/ord_alphlong/helper3.c | 75 | ||||
| -rwxr-xr-x | exam_final/rendu/ord_alphlong/include.h | 42 | ||||
| -rwxr-xr-x | exam_final/rendu/ord_alphlong/main.c | 32 | ||||
| -rwxr-xr-x | exam_final/rendu/rotone/rotone.c | 50 | ||||
| -rwxr-xr-x | exam_final/rendu/sort_list/sort_list.c | 49 |
20 files changed, 1098 insertions, 0 deletions
diff --git a/exam_final/rendu/__GIT_HISTORY b/exam_final/rendu/__GIT_HISTORY new file mode 100755 index 0000000..6286ca2 --- /dev/null +++ b/exam_final/rendu/__GIT_HISTORY @@ -0,0 +1,122 @@ +commit 34f8b0fa88a10c6066047c6fd5902a1f61fb7139 +Author: Exam 42 <exam-no-reply@42.fr> +Date: Fri Jul 26 17:45:42 2019 +0200 + + brainfuck + + brainfuck/brainfuck.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++ + brainfuck/stack.c | 42 +++++++++++++++++++++++++ + brainfuck/stack.h | 26 ++++++++++++++++ + 3 files changed, 153 insertions(+) + +commit b3f3fe0a53e3b5dfe186cbf50701ff9047f37705 +Author: Exam 42 <exam-no-reply@42.fr> +Date: Fri Jul 26 16:39:24 2019 +0200 + + ord_alphlong + + ord_alphlong/helper.c | 52 ++++++++++++++++++++++++++++++++++ + ord_alphlong/helper2.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++ + ord_alphlong/helper3.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++ + ord_alphlong/include.h | 42 +++++++++++++++++++++++++++ + ord_alphlong/main.c | 32 +++++++++++++++++++++ + 5 files changed, 278 insertions(+) + +commit 80849735bdeb1452a6275fee2594b1407e9afcce +Author: Exam 42 <exam-no-reply@42.fr> +Date: Fri Jul 26 14:31:26 2019 +0200 + + count_alpha + + count_alpha/count_alpha.c | 109 ++++++++++++++++++++++++++++++++++++++++++++++ + 1 file changed, 109 insertions(+) + +commit e198992e2e0673e33fecd38897f3fc41b186c82c +Author: Exam 42 <exam-no-reply@42.fr> +Date: Fri Jul 26 13:34:08 2019 +0200 + + sort_list + + sort_list/sort_list.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ + 1 file changed, 49 insertions(+) + +commit 2f7b14a42f21d2598b99d668cbd75c121fa0e28e +Author: Exam 42 <exam-no-reply@42.fr> +Date: Fri Jul 26 13:09:52 2019 +0200 + + ft_split + + ft_split/ft_split.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++ + 1 file changed, 74 insertions(+) + +commit 1b5c95b498c6286a77677a1c101a8208e56af4ce +Author: Exam 42 <exam-no-reply@42.fr> +Date: Fri Jul 26 12:33:28 2019 +0200 + + ft_itoa + + ft_itoa/ft_itoa.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ + 1 file changed, 64 insertions(+) + +commit 329e7a2c15e26d350d651af2571829c2a25c0666 +Author: Exam 42 <exam-no-reply@42.fr> +Date: Fri Jul 26 11:33:31 2019 +0200 + + ft_atoi + + ft_atoi/ft_atoi.c | 38 ++++++++++++++++++++++++++++++++++++++ + 1 file changed, 38 insertions(+) + +commit cb2d8246d609fc0d347f19124e57e516f2360c59 +Author: Exam 42 <exam-no-reply@42.fr> +Date: Fri Jul 26 11:09:08 2019 +0200 + + last_word + + last_word/last_word.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ + 1 file changed, 50 insertions(+) + +commit 93bec2c03948516c977dc726ebcbd29d1cf87af2 +Author: Exam 42 <exam-no-reply@42.fr> +Date: Fri Jul 26 10:41:13 2019 +0200 + + ft_strrev + + ft_strrev/ft_strrev.c | 40 ++++++++++++++++++++++++++++++++++++++++ + 1 file changed, 40 insertions(+) + +commit 22e59a40561ff53f5f65d90d48d7061bfc4f9280 +Author: Exam 42 <exam-no-reply@42.fr> +Date: Fri Jul 26 10:32:44 2019 +0200 + + rotone + + rotone/rotone.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ + 1 file changed, 50 insertions(+) + +commit 41aa95d06869add95fa1078bd18b1d58122fa011 +Author: Exam 42 <exam-no-reply@42.fr> +Date: Fri Jul 26 10:14:58 2019 +0200 + + aff_last_param + + aff_last_param/aff_last_param.c | 31 +++++++++++++++++++++++++++++++ + 1 file changed, 31 insertions(+) + +commit a338cec36af53b43e95ff0de679288068b212a22 +Author: Exam 42 <exam-no-reply@42.fr> +Date: Fri Jul 26 10:08:09 2019 +0200 + + ft_putstr + + ft_putstr/ft_putstr.c | 19 +++++++++++++++++++ + 1 file changed, 19 insertions(+) + +commit de79154201b309ec32e35f5a26dc675a3c4e0b1e +Author: Exam 42 <exam-no-reply@42.fr> +Date: Fri Jul 26 10:05:03 2019 +0200 + + aff_z + + aff_z/aff_z.c | 21 +++++++++++++++++++++ + 1 file changed, 21 insertions(+) diff --git a/exam_final/rendu/aff_last_param/aff_last_param.c b/exam_final/rendu/aff_last_param/aff_last_param.c new file mode 100755 index 0000000..27a024a --- /dev/null +++ b/exam_final/rendu/aff_last_param/aff_last_param.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* aff_last_param.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: exam <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/26 10:09:02 by exam #+# #+# */ +/* Updated: 2019/07/26 10:13:09 by exam ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include <unistd.h> + +int ft_strlen(char *str) +{ + int counter; + + counter = 0; + while (str[counter]) + counter++; + return (counter); +} + +int main(int argc, char **argv) +{ + if (argc != 1) + write(1, argv[argc - 1], ft_strlen(argv[argc - 1])); + write(1, "\n", 1); + return (0); +} diff --git a/exam_final/rendu/aff_z/aff_z.c b/exam_final/rendu/aff_z/aff_z.c new file mode 100755 index 0000000..3cb7625 --- /dev/null +++ b/exam_final/rendu/aff_z/aff_z.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* aff_z.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: exam <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/26 10:00:33 by exam #+# #+# */ +/* Updated: 2019/07/26 10:02:22 by exam ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include <unistd.h> + +int main(int argc, char **argv) +{ + (void)argc; + (void)argv; + write(STDOUT_FILENO, "z\n", 2); + return (0); +} diff --git a/exam_final/rendu/brainfuck/brainfuck.c b/exam_final/rendu/brainfuck/brainfuck.c new file mode 100755 index 0000000..4cd619d --- /dev/null +++ b/exam_final/rendu/brainfuck/brainfuck.c @@ -0,0 +1,85 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* brainfuck.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: exam <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/26 16:42:44 by exam #+# #+# */ +/* Updated: 2019/07/26 17:43:25 by exam ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "stack.h" +#include <stdlib.h> +#include <unistd.h> + +void go_close(char **str) +{ + t_stack *st; + + st = create_elem(**str); + while (st != NULL) + { + (*str)++; + if (**str == '[') + st = push(st, '['); + if (**str == ']') + st = pop(st); + } +} + +void go_open(char **str) +{ + t_stack *st; + + st = create_elem(**str); + while (st != NULL) + { + (*str)--; + if (**str == ']') + st = push(st, ']'); + if (**str == '[') + st = pop(st); + } +} + +int main(int argc, char **argv) +{ + char *ptr; + char *origin; + char *str; + int i; + + if (argc != 2) + { + write(1, "\n", 1); + return (0); + } + origin = (char*)malloc(2048); + ptr = origin; + i = 0; + while (i < 2048) + ptr[i++] = 0; + str = argv[1]; + while (*str) + { + if (*str == '>') + ptr++; + else if (*str == '<') + ptr--; + else if (*str == '+') + (*ptr)++; + else if (*str == '-') + (*ptr)--; + else if (*str == '.') + write(1, ptr, 1); + else if (*str == '[' && *ptr == 0) + go_close(&str); + else if (*str == ']' && *ptr != 0) + go_open(&str); + str++; + } + free(origin); + return (0); +} diff --git a/exam_final/rendu/brainfuck/stack.c b/exam_final/rendu/brainfuck/stack.c new file mode 100755 index 0000000..c79c039 --- /dev/null +++ b/exam_final/rendu/brainfuck/stack.c @@ -0,0 +1,42 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* stack.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: exam <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/26 17:28:55 by exam #+# #+# */ +/* Updated: 2019/07/26 17:40:35 by exam ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include <stdlib.h> +#include "stack.h" + +t_stack *create_elem(char data) +{ + t_stack *elem; + + elem = malloc(sizeof(t_stack)); + elem->data = data; + elem->next = NULL; + return (elem); +} + +t_stack *push(t_stack *stack, char data) +{ + t_stack *elem; + + elem = create_elem(data); + elem->next = stack; + return (elem); +} + +t_stack *pop(t_stack *stack) +{ + t_stack *tmp; + + tmp = stack->next; + free(stack); + return (tmp); +} diff --git a/exam_final/rendu/brainfuck/stack.h b/exam_final/rendu/brainfuck/stack.h new file mode 100755 index 0000000..6d0d57b --- /dev/null +++ b/exam_final/rendu/brainfuck/stack.h @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* stack.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: exam <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/26 17:33:37 by exam #+# #+# */ +/* Updated: 2019/07/26 17:39:15 by exam ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef STACK_H +# define STACK_H + +typedef struct s_stack +{ + char data; + struct s_stack *next; +} t_stack; + +t_stack *push(t_stack *stack, char data); +t_stack *create_elem(char data); +t_stack *pop(t_stack *stack); + +#endif diff --git a/exam_final/rendu/count_alpha/count_alpha.c b/exam_final/rendu/count_alpha/count_alpha.c new file mode 100755 index 0000000..ed502a5 --- /dev/null +++ b/exam_final/rendu/count_alpha/count_alpha.c @@ -0,0 +1,109 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* count_alpha.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: exam <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/26 13:36:33 by exam #+# #+# */ +/* Updated: 2019/07/26 14:30:23 by exam ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include <stdio.h> +#include <unistd.h> + +typedef struct s_counter +{ + char letter; + int count; +} t_counter; + +int in_counters(t_counter *counters, char c) +{ + int i; + + i = 0; + while (counters[i].letter) + { + if (c == counters[i].letter) + return (1); + i++; + } + return (0); +} + +void str_tolow(char *str) +{ + while (*str) + { + if (*str >= 'A' && *str <= 'Z') + *str += 'a' - 'A'; + str++; + } +} + +int count_char(char c, char *str) +{ + int counter; + + counter = 0; + while (*str) + { + if (c == *str) + counter++; + str++; + } + return (counter); +} + +void print_counters(t_counter *counters, int size) +{ + int i; + + i = 0; + while (i < size) + { + if (counters[i].count != 0) + { + printf("%d%c", counters[i].count, counters[i].letter); + if (i != size - 1) + printf(", "); + } + i++; + } +} + +int main(int argc, char **argv) +{ + t_counter counters[26]; + int i; + int j; + + if (argc == 2) + { + i = 0; + j = 0; + while (i < 26) + { + counters[i].letter = '\0'; + counters[i].count = 0; + i++; + } + str_tolow(argv[1]); + i = 0; + while (argv[1][i]) + { + if (argv[1][i] >= 'a' && argv[1][i] <= 'z' && !in_counters(counters, argv[1][i])) + { + counters[j].letter = argv[1][i]; + counters[j].count = count_char(argv[1][i], argv[1]); + j++; + } + i++; + } + print_counters(counters, j); + } + printf("\n"); + return (0); +} diff --git a/exam_final/rendu/ft_atoi/ft_atoi.c b/exam_final/rendu/ft_atoi/ft_atoi.c new file mode 100755 index 0000000..2f125bf --- /dev/null +++ b/exam_final/rendu/ft_atoi/ft_atoi.c @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_atoi.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: exam <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/26 11:11:42 by exam #+# #+# */ +/* Updated: 2019/07/26 11:32:51 by exam ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_atoi(const char *str) +{ + int nb; + int is_negative; + + while (*str == ' ' || *str == '\t' || *str == '\n' || *str == '\r' + || *str == '\v' || *str == '\f'|| *str == '\r') + str++; + is_negative = 0; + if (*str == '+' || *str == '-') + { + if (*str == '-') + is_negative = 1; + str++; + } + nb = 0; + while (*str >= '0' && *str <= '9') + { + nb *= 10; + nb += *str - '0'; + str++; + } + if (is_negative) + nb = -nb; + return (nb); +} diff --git a/exam_final/rendu/ft_itoa/ft_itoa.c b/exam_final/rendu/ft_itoa/ft_itoa.c new file mode 100755 index 0000000..308cb41 --- /dev/null +++ b/exam_final/rendu/ft_itoa/ft_itoa.c @@ -0,0 +1,64 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_itoa.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: exam <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/26 11:35:43 by exam #+# #+# */ +/* Updated: 2019/07/26 12:32:57 by exam ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include <stdlib.h> + +int count_len(int nbr) +{ + int counter; + unsigned int u_nbr; + + if (nbr == 0) + return (1); + counter = 0; + u_nbr = nbr; + if (nbr < 0) + { + counter++; + u_nbr = -nbr; + } + while (u_nbr > 0) + { + u_nbr /= 10; + counter++; + } + return (counter); +} + +char *ft_itoa(int nbr) +{ + char *str; + int len; + int is_negative; + unsigned int u_nbr; + + len = count_len(nbr); + if ((str = (char*)malloc(sizeof(char) * (len + 1))) == NULL) + return (NULL); + str[len] = '\0'; + is_negative = 0; + u_nbr = nbr; + if (nbr < 0) + { + is_negative = 1; + str[0] = '-'; + u_nbr = -nbr; + } + len--; + while (len >= (is_negative ? 1 : 0)) + { + str[len] = u_nbr % 10 + '0'; + u_nbr /= 10; + len--; + } + return (str); +} diff --git a/exam_final/rendu/ft_putstr/ft_putstr.c b/exam_final/rendu/ft_putstr/ft_putstr.c new file mode 100755 index 0000000..3733591 --- /dev/null +++ b/exam_final/rendu/ft_putstr/ft_putstr.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putstr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: exam <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/26 10:05:51 by exam #+# #+# */ +/* Updated: 2019/07/26 10:07:27 by exam ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include <unistd.h> + +void ft_putstr(char *str) +{ + while (*str) + write(STDOUT_FILENO, str++, 1); +} diff --git a/exam_final/rendu/ft_split/ft_split.c b/exam_final/rendu/ft_split/ft_split.c new file mode 100755 index 0000000..75d9f8d --- /dev/null +++ b/exam_final/rendu/ft_split/ft_split.c @@ -0,0 +1,74 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_split.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: exam <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/26 12:35:48 by exam #+# #+# */ +/* Updated: 2019/07/26 13:09:10 by exam ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include <stdlib.h> + +int in_charset(char c) +{ + return (c == ' ' || c == '\n' || c == '\t'); +} + +int count_segment(char *str) +{ + int counter; + + counter = 0; + while (*str) + { + if (in_charset(*str)) + { + str++; + continue ; + } + counter++; + while (*str && !in_charset(*str)) + str++; + } + return (counter); +} + +char **ft_split(char *str) +{ + char **strs; + char *tmp; + int size; + int i; + int j; + + size = count_segment(str); + if ((strs = (char**)malloc(sizeof(char*) * (size + 1))) == NULL) + return (NULL); + i = 0; + while (i < size) + { + if (*str && in_charset(*str)) + { + str++; + continue ; + } + j = 0; + while (str[j] && !in_charset(str[j])) + j++; + if ((tmp = (char*)malloc(sizeof(char) * (j + 1))) == NULL) + return (NULL); + j = 0; + while (*str && !in_charset(*str)) + { + tmp[j] = *str++; + j++; + } + tmp[j] = '\0'; + strs[i++] = tmp; + } + strs[i] = NULL; + return (strs); +} diff --git a/exam_final/rendu/ft_strrev/ft_strrev.c b/exam_final/rendu/ft_strrev/ft_strrev.c new file mode 100755 index 0000000..685dd70 --- /dev/null +++ b/exam_final/rendu/ft_strrev/ft_strrev.c @@ -0,0 +1,40 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strrev.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: exam <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/26 10:34:13 by exam #+# #+# */ +/* Updated: 2019/07/26 10:40:13 by exam ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_strlen(char *str) +{ + int counter; + + counter = 0; + while (str[counter]) + counter++; + return (counter); +} + +char *ft_strrev(char *str) +{ + int i; + int j; + char tmp; + + i = 0; + j = ft_strlen(str) - 1; + while (i < j) + { + tmp = str[i]; + str[i] = str[j]; + str[j] = tmp; + i++; + j--; + } + return (str); +} diff --git a/exam_final/rendu/last_word/last_word.c b/exam_final/rendu/last_word/last_word.c new file mode 100755 index 0000000..f8bdb11 --- /dev/null +++ b/exam_final/rendu/last_word/last_word.c @@ -0,0 +1,50 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* last_word.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: exam <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/26 10:42:10 by exam #+# #+# */ +/* Updated: 2019/07/26 11:05:51 by exam ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include <unistd.h> + +int ft_strlen(char *str) +{ + int counter; + + counter = 0; + while (str[counter]) + counter++; + return (counter); +} + +int is_space(char c) +{ + return (c == ' ' || c == '\t'); +} + +int main(int argc, char **argv) +{ + int i; + + if (argc == 2) + { + i = ft_strlen(argv[1]) - 1; + while (i > -1 && is_space(argv[1][i])) + i--; + while (i > -1 && !is_space(argv[1][i])) + i--; + i++; + while (i >= 0 && argv[1][i] && !is_space(argv[1][i])) + { + write(1, &argv[1][i], 1); + i++; + } + } + write(1, "\n", 1); + return (0); +} diff --git a/exam_final/rendu/ord_alphlong/helper.c b/exam_final/rendu/ord_alphlong/helper.c new file mode 100755 index 0000000..7d285c1 --- /dev/null +++ b/exam_final/rendu/ord_alphlong/helper.c @@ -0,0 +1,52 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* helper.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: exam <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/26 14:40:48 by exam #+# #+# */ +/* Updated: 2019/07/26 16:35:08 by exam ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include <stdlib.h> +#include <unistd.h> +#include "include.h" + +int ft_strlen(char *str) +{ + int counter; + + counter = 0; + while (str[counter]) + counter++; + return (counter); +} + +int letter_diff(char a, char b) +{ + if (b >= 'A' && b <= 'Z') + b += 'a' - 'A'; + if (a >= 'A' && a <= 'Z') + a += 'a' - 'A'; + return (a - b); +} + +void ft_putstr(char *str) +{ + while (*str) + write(1, str++, 1); +} + +int str_lettercmp(char *s1, char *s2) +{ + if (ft_strlen(s1) != ft_strlen(s2)) + return (-1); + while (*s1 && *s2 && letter_diff(*s1, *s2) == 0) + { + s1++; + s2++; + } + return (letter_diff(*s1, *s2)); +} diff --git a/exam_final/rendu/ord_alphlong/helper2.c b/exam_final/rendu/ord_alphlong/helper2.c new file mode 100755 index 0000000..431274b --- /dev/null +++ b/exam_final/rendu/ord_alphlong/helper2.c @@ -0,0 +1,77 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* helper2.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: exam <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/26 15:20:07 by exam #+# #+# */ +/* Updated: 2019/07/26 16:29:42 by exam ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include <stdlib.h> +#include "include.h" + +int sorted(char **strs, int cmp(char*, char*)) +{ + int i; + + i = 0; + if (strs[0] == NULL) + return (1); + while (strs[i + 1] != NULL) + { + if ((*cmp)(strs[i], strs[i + 1]) > 0) + return (0); + i++; + } + return (1); +} + +void sort_strs(char **strs, int cmp(char*, char*)) +{ + int i; + char *tmp; + + while (!sorted(strs, cmp)) + { + i = 0; + while (strs[i + 1] != NULL) + { + if ((*cmp)(strs[i], strs[i + 1]) > 0) + { + tmp = strs[i]; + strs[i] = strs[i + 1]; + strs[i + 1] = tmp; + } + i++; + } + } +} + +int strlen_cmp(char *s1, char *s2) +{ + return (ft_strlen(s1) - ft_strlen(s2)); +} + +void print_strs(char **strs) +{ + int i; + int len; + + i = 0; + while (strs[i] != NULL) + { + len = ft_strlen(strs[i]); + while (strs[i] && ft_strlen(strs[i]) == len) + { + ft_putstr(strs[i]); + if (strs[i + 1] != NULL && ft_strlen(strs[i + 1]) == len) + ft_putstr(" "); + else + ft_putstr("\n"); + i++; + } + } +} diff --git a/exam_final/rendu/ord_alphlong/helper3.c b/exam_final/rendu/ord_alphlong/helper3.c new file mode 100755 index 0000000..83b548a --- /dev/null +++ b/exam_final/rendu/ord_alphlong/helper3.c @@ -0,0 +1,75 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ |
