diff options
| author | Charles <sircharlesaze@gmail.com> | 2019-07-24 18:57:19 +0200 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2019-07-24 18:57:19 +0200 |
| commit | 475449dd4b1f3308bac6f72c34d87812216a0738 (patch) | |
| tree | 319a76f0e87b041818156f2d1dfbbc6a7dfacf06 /exam02/rendu/inter/inter.c | |
| parent | 83edb77d74bb339f3e1324a51039c78ac503db90 (diff) | |
| download | piscine-475449dd4b1f3308bac6f72c34d87812216a0738.tar.gz piscine-475449dd4b1f3308bac6f72c34d87812216a0738.tar.bz2 piscine-475449dd4b1f3308bac6f72c34d87812216a0738.zip | |
exam02
Diffstat (limited to 'exam02/rendu/inter/inter.c')
| -rwxr-xr-x | exam02/rendu/inter/inter.c | 64 |
1 files changed, 64 insertions, 0 deletions
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); +} |
