diff options
| author | Charles <sircharlesaze@gmail.com> | 2019-07-16 12:58:13 +0200 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2019-07-16 12:58:13 +0200 |
| commit | 14914f50c3de6c5444e13cf67db064b03c1c90ef (patch) | |
| tree | 3ecf5a41b4541980ba0287a431681cd5ae25ad84 /exam01/rendu | |
| parent | 217bcb0d4e3ba60604921cb40d5a11a64f93cfc7 (diff) | |
| download | piscine-14914f50c3de6c5444e13cf67db064b03c1c90ef.tar.gz piscine-14914f50c3de6c5444e13cf67db064b03c1c90ef.tar.bz2 piscine-14914f50c3de6c5444e13cf67db064b03c1c90ef.zip | |
c09 passed, c10 start, exam00 and exam01
Diffstat (limited to 'exam01/rendu')
| -rwxr-xr-x | exam01/rendu/__GIT_HISTORY | 71 | ||||
| -rwxr-xr-x | exam01/rendu/ft_range/ft_range.c | 40 | ||||
| -rwxr-xr-x | exam01/rendu/ft_split/ft_split.c | 72 | ||||
| -rwxr-xr-x | exam01/rendu/hello/hello.c | 18 | ||||
| -rwxr-xr-x | exam01/rendu/rev_print/rev_print.c | 32 | ||||
| -rwxr-xr-x | exam01/rendu/rotone/rotone.c | 39 | ||||
| -rwxr-xr-x | exam01/rendu/wdmatch/wdmatch.c | 54 |
7 files changed, 326 insertions, 0 deletions
diff --git a/exam01/rendu/__GIT_HISTORY b/exam01/rendu/__GIT_HISTORY new file mode 100755 index 0000000..07c2777 --- /dev/null +++ b/exam01/rendu/__GIT_HISTORY @@ -0,0 +1,71 @@ +commit 45e8e511bd3d91e4cc7d44cef1257914d442541c +Author: Exam 42 <exam-no-reply@42.fr> +Date: Fri Jul 12 19:28:29 2019 +0200 + + ft_split + + ft_split/ft_split.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++ + 1 file changed, 72 insertions(+) + +commit 3f66b01dadeabbfb7332ca8eaff6c651baa7d60c +Author: Exam 42 <exam-no-reply@42.fr> +Date: Fri Jul 12 18:33:39 2019 +0200 + + overme + + ft_range/ft_range.c | 9 +++++---- + 1 file changed, 5 insertions(+), 4 deletions(-) + +commit 2fa3ca5efbeea644b056cbaa24c006cb475f1d68 +Author: Exam 42 <exam-no-reply@42.fr> +Date: Fri Jul 12 18:22:27 2019 +0200 + + ft_range + + ft_range/ft_range.c | 39 +++++++++++++++++++++++++++++++++++++++ + 1 file changed, 39 insertions(+) + +commit b9247efc1f78a0f27a5e8cb097a6d09316541982 +Author: Exam 42 <exam-no-reply@42.fr> +Date: Fri Jul 12 17:58:16 2019 +0200 + + k you dumb fuck + + wdmatch/wdmatch.c | 3 +-- + 1 file changed, 1 insertion(+), 2 deletions(-) + +commit 79c5bf10efda0eead115b274dac91ad92587a53d +Author: Exam 42 <exam-no-reply@42.fr> +Date: Fri Jul 12 17:55:47 2019 +0200 + + wdmatch + + wdmatch/wdmatch.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ + 1 file changed, 55 insertions(+) + +commit 39cdf357b40ced49f3ac6290d932c7801816115d +Author: Exam 42 <exam-no-reply@42.fr> +Date: Fri Jul 12 17:22:53 2019 +0200 + + rotone + + rotone/rotone.c | 39 +++++++++++++++++++++++++++++++++++++++ + 1 file changed, 39 insertions(+) + +commit c265e4850d0962b936392aca4f3fd6668bd213b2 +Author: Exam 42 <exam-no-reply@42.fr> +Date: Fri Jul 12 17:11:27 2019 +0200 + + rev_print + + rev_print/rev_print.c | 32 ++++++++++++++++++++++++++++++++ + 1 file changed, 32 insertions(+) + +commit 9addd4166252d59255a58e3c6c1c7a1e926b37d3 +Author: Exam 42 <exam-no-reply@42.fr> +Date: Fri Jul 12 17:04:19 2019 +0200 + + hello + + hello/hello.c | 18 ++++++++++++++++++ + 1 file changed, 18 insertions(+) diff --git a/exam01/rendu/ft_range/ft_range.c b/exam01/rendu/ft_range/ft_range.c new file mode 100755 index 0000000..de8c414 --- /dev/null +++ b/exam01/rendu/ft_range/ft_range.c @@ -0,0 +1,40 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_range.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: exam <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/12 18:00:18 by exam #+# #+# */ +/* Updated: 2019/07/12 18:32:44 by exam ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include <stdlib.h> + +int *ft_range(int start, int end) +{ + int *range; + int i; + + range = (int*)malloc(sizeof(int) * + (end - start < 0 ? start - end : end - start + 1)); + if (range == NULL) + return (NULL); + i = 0; + if (start < end) + while (start <= end) + { + range[i] = start; + start++; + i++; + } + else + while (start >= end) + { + range[i] = start; + start--; + i++; + } + return (range); +} diff --git a/exam01/rendu/ft_split/ft_split.c b/exam01/rendu/ft_split/ft_split.c new file mode 100755 index 0000000..7c8e5c7 --- /dev/null +++ b/exam01/rendu/ft_split/ft_split.c @@ -0,0 +1,72 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_split.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: exam <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/12 18:35:38 by exam #+# #+# */ +/* Updated: 2019/07/12 19:27:00 by exam ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include <stdlib.h> + +#define ISSEP(c) (c == ' ' || c == '\n' || c == '\t') + +int count_segment(char *str) +{ + int counter; + + counter = 0; + while (*str) + { + if (!ISSEP(*str)) + { + counter++; + while (*str && !ISSEP(*str)) + str++; + if (!*str) + break; + } + str++; + } + return (counter); +} + +char **ft_split(char *str) +{ + char **split; + char *tmp; + int i; + int j; + int segments; + + segments = count_segment(str); + split = (char**)malloc(sizeof(char*) * segments + 1); + if (split == NULL) + return (NULL); + j = 0; + while (j < segments) + { + if (ISSEP(*str)) + { + str++; + continue; + } + i = 0; + while (!ISSEP(str[i])) + i++; + tmp = (char*)malloc(sizeof(char) * i + 1); + if (tmp == NULL) + return (NULL); + i = 0; + while (!ISSEP(*str)) + tmp[i++] = *str++; + tmp[i] = '\0'; + split[j] = tmp; + j++; + } + split[j] = NULL; + return (split); +} diff --git a/exam01/rendu/hello/hello.c b/exam01/rendu/hello/hello.c new file mode 100755 index 0000000..0becc7e --- /dev/null +++ b/exam01/rendu/hello/hello.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* hello.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: exam <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/12 17:01:31 by exam #+# #+# */ +/* Updated: 2019/07/12 17:03:00 by exam ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include <unistd.h> + +int main(void) +{ + write(1, "Hello World!\n", 13); +} diff --git a/exam01/rendu/rev_print/rev_print.c b/exam01/rendu/rev_print/rev_print.c new file mode 100755 index 0000000..b46a2d6 --- /dev/null +++ b/exam01/rendu/rev_print/rev_print.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* rev_print.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: exam <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/12 17:06:11 by exam #+# #+# */ +/* Updated: 2019/07/12 17:10:21 by exam ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include <unistd.h> + +int main(int argc, char **argv) +{ + int i; + + if (argc == 1 || argc > 2) + { + write(1, "\n", 1); + return (0); + } + + i = 0; + while (argv[1][i]) + i++; + while (i-- > 0) + write(1, &argv[1][i], 1); + write(1, "\n", 1); + return (0); +} diff --git a/exam01/rendu/rotone/rotone.c b/exam01/rendu/rotone/rotone.c new file mode 100755 index 0000000..55a6ef5 --- /dev/null +++ b/exam01/rendu/rotone/rotone.c @@ -0,0 +1,39 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* rotone.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: exam <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/12 17:12:59 by exam #+# #+# */ +/* Updated: 2019/07/12 17:21:12 by exam ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include <unistd.h> + +void ft_putchar(char c) +{ + write(1, &c, 1); +} + +int main(int argc, char **argv) +{ + if (argc == 1 || argc > 2) + { + write(1, "\n", 1); + return (0); + } + while (*argv[1]) + { + if (*argv[1] >= 'a' && *argv[1] <= 'z') + ft_putchar(*argv[1] == 'z' ? 'a' : *argv[1] + 1); + else if (*argv[1] >= 'A' && *argv[1] <= 'Z') + ft_putchar(*argv[1] == 'Z' ? 'A' : *argv[1] + 1); + else + ft_putchar(*argv[1]); + argv[1]++; + } + write(1, "\n", 1); + return (0); +} diff --git a/exam01/rendu/wdmatch/wdmatch.c b/exam01/rendu/wdmatch/wdmatch.c new file mode 100755 index 0000000..96242c9 --- /dev/null +++ b/exam01/rendu/wdmatch/wdmatch.c @@ -0,0 +1,54 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* wdmatch.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: exam <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/12 17:25:25 by exam #+# #+# */ +/* Updated: 2019/07/12 17:57:14 by exam ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include <unistd.h> + +int in_charset(char c, char *charset) +{ + while (*charset) + if (c == *charset++) + return (1); + return (0); +} + +int main(int argc, char **argv) +{ + int i; + int j; + char *str; + char *charset; + + if (argc != 3) + { + write(1, "\n", 1); + return (0); + } + str = argv[1]; + charset = argv[2]; + i = 0; + j = 0; + while (str[i]) + { + if (!in_charset(str[i], charset)) + { + write(1, "\n", 1); + return (0); + } + while (*charset != str[i]) + charset++; + i++; + } + while (*str) + write(1, str++, 1); + write(1, "\n", 1); + return (0); +} |
