diff options
| author | Cabergs Charles <cacharle@e-r6-p7.s19.be> | 2019-07-09 10:23:25 +0200 |
|---|---|---|
| committer | Cabergs Charles <cacharle@e-r6-p7.s19.be> | 2019-07-09 10:23:25 +0200 |
| commit | 90076f97a1de6b60968e98d6c7a8b520ebda3c8e (patch) | |
| tree | 6c60a0fde7b2d8bc984845f6a412171df977e1dc /c07 | |
| parent | 803d5e42138e1f0f69f6d8953aea5cd23f5b72ee (diff) | |
| download | piscine-90076f97a1de6b60968e98d6c7a8b520ebda3c8e.tar.gz piscine-90076f97a1de6b60968e98d6c7a8b520ebda3c8e.tar.bz2 piscine-90076f97a1de6b60968e98d6c7a8b520ebda3c8e.zip | |
c07/c08 start, c05 faster, better, stronger
Diffstat (limited to 'c07')
| -rw-r--r-- | c07/ex00/ft_strdup.c | 4 | ||||
| -rw-r--r-- | c07/ex01/ft_range.c | 8 | ||||
| -rw-r--r-- | c07/ex02/ft_ultimate_range.c | 4 | ||||
| -rw-r--r-- | c07/ex03/ft_strjoin.c | 13 | ||||
| -rw-r--r-- | c07/ex04/ft_convert_base.c | 65 | ||||
| -rw-r--r-- | c07/ex04/ft_convert_base2.c | 0 | ||||
| -rw-r--r-- | c07/ex05/ft_split.c | 49 | ||||
| -rw-r--r-- | c07/main.c | 17 |
8 files changed, 139 insertions, 21 deletions
diff --git a/c07/ex00/ft_strdup.c b/c07/ex00/ft_strdup.c index c63bd27..e53a3af 100644 --- a/c07/ex00/ft_strdup.c +++ b/c07/ex00/ft_strdup.c @@ -6,7 +6,7 @@ /* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/07 15:39:50 by cacharle #+# #+# */ -/* Updated: 2019/07/08 07:49:52 by cacharle ### ########.fr */ +/* Updated: 2019/07/09 07:36:10 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -28,7 +28,7 @@ char *ft_strdup(char *src) int i; char *dup_ptr; - dup_ptr = malloc(sizeof(char) * ft_strlen(src)); + dup_ptr = (char*)malloc(sizeof(char) * ft_strlen(src)); if (dup_ptr == NULL) { errno = ENOMEM; diff --git a/c07/ex01/ft_range.c b/c07/ex01/ft_range.c index be171f3..669f663 100644 --- a/c07/ex01/ft_range.c +++ b/c07/ex01/ft_range.c @@ -6,18 +6,20 @@ /* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/07 16:03:47 by cacharle #+# #+# */ -/* Updated: 2019/07/08 08:03:28 by cacharle ### ########.fr */ +/* Updated: 2019/07/09 07:46:19 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ -int *ft_range(int min, int max) +#include <stdlib.h> + +int *ft_range(int min, int max) { int i; int *range; if (min >= max) return (NULL); - range = malloc(sizeof(int) * (max - min)); + range = (int*)malloc(sizeof(int) * (max - min)); i = 0; while (i < max - min) { diff --git a/c07/ex02/ft_ultimate_range.c b/c07/ex02/ft_ultimate_range.c index 141889c..d254ed1 100644 --- a/c07/ex02/ft_ultimate_range.c +++ b/c07/ex02/ft_ultimate_range.c @@ -6,13 +6,13 @@ /* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/07 16:09:06 by cacharle #+# #+# */ -/* Updated: 2019/07/08 08:38:29 by cacharle ### ########.fr */ +/* Updated: 2019/07/09 07:46:19 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ #include <stdlib.h> -int ft_ultimate_range(int **range, int min, int max) +int ft_ultimate_range(int **range, int min, int max) { int i; diff --git a/c07/ex03/ft_strjoin.c b/c07/ex03/ft_strjoin.c index 1264000..ea97bb6 100644 --- a/c07/ex03/ft_strjoin.c +++ b/c07/ex03/ft_strjoin.c @@ -6,7 +6,7 @@ /* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/07 16:14:25 by cacharle #+# #+# */ -/* Updated: 2019/07/08 11:08:00 by cacharle ### ########.fr */ +/* Updated: 2019/07/09 09:08:52 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,7 +17,7 @@ int my_strlen(char *str) int i; i = 0; - while(str[i]) + while (str[i]) i++; return (i); } @@ -31,12 +31,7 @@ int cummulative_strlen(int size, char **strs) i = 0; while (size > 0) { - i = 0; - while (strs[size - 1][i]) - { - i++; - len++; - } + len += my_strlen(strs[size - 1]); size--; } return (len); @@ -51,7 +46,7 @@ char *ft_strjoin(int size, char **strs, char *sep) char *join; join = (char*)malloc(sizeof(char) * (cummulative_strlen(size, strs) - + my_strlen(sep) * (size - 1))); + + my_strlen(sep) * (size - 1) + 1)); j = 0; l = 0; while (l < size) diff --git a/c07/ex04/ft_convert_base.c b/c07/ex04/ft_convert_base.c new file mode 100644 index 0000000..f50289a --- /dev/null +++ b/c07/ex04/ft_convert_base.c @@ -0,0 +1,65 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_convert_base.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/08 16:16:53 by cacharle #+# #+# */ +/* Updated: 2019/07/09 09:05:47 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int check_base(char *base) +{ + int i; + int j; + + i = 0; + while (base[i]) + { + if (base[i] == '-' || base[i] == '+' || base[i] == ' ' + || base[i] == '\t' || base[i] == '\n' || base[i] == '\v' + || base[i] == '\f' || base[i] == '\r') + return (0); + j = 0; + while (base[j]) + { + if (j != i && base[j] == base[i]) + return (0); + j++; + } + i++; + } + if (i < 2) + return (0); + return (1); +} + +int ft_pow(int base, int exponent) +{ + int accumulator; + + accumulator = 1; + while (exponent-- > 0) + accumulator *= base; + return (accumulator); +} + +int ft_atoi_base(char *nbr, char *base) +{ + +} + +char *ft_convert_base(char *nbr, char *base_from, char *base_to) +{ + int converted_nb; + char *converted_to + + if (!check_base(base_from) || !check_base(base_to)) + return (NULL); + converted_nb = ft_atoi_base(nbr, base_from); + printf("%d\n", convert_nb); + /*converted_to = ft_itoa_base(converted_nb, base_to);*/ + /*return (converted_to);*/ +} diff --git a/c07/ex04/ft_convert_base2.c b/c07/ex04/ft_convert_base2.c new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/c07/ex04/ft_convert_base2.c diff --git a/c07/ex05/ft_split.c b/c07/ex05/ft_split.c new file mode 100644 index 0000000..da2d7fc --- /dev/null +++ b/c07/ex05/ft_split.c @@ -0,0 +1,49 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_split.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/08 15:58:03 by cacharle #+# #+# */ +/* Updated: 2019/07/09 09:40:49 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include <stdlib.h> + +int count_segment(char *str, char *charset) +{ + int counter; + int i; + + counter = 0; + while (*str) + { + i = 0; + while (charset[i]) + if (str++ == charset[i++]) + counter++; + str++; + } + return (counter); +} + +int strlen_until_sep(char *str, char *charset) +{ + +} + +char **ft_split(char *str, char *charset) +{ + char **strs; + + strs = (char**)malloc(sizeof(char*) * count_segment(str, charset)); + printf("%d\n", count_segment(str, charset)); + /*while (*str)*/ + /*{*/ + + /*str++;*/ + /*}*/ + return (strs); +} @@ -6,7 +6,7 @@ /* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/08 08:19:02 by cacharle #+# #+# */ -/* Updated: 2019/07/08 11:00:55 by cacharle ### ########.fr */ +/* Updated: 2019/07/09 09:42:11 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,7 +18,7 @@ #include "ex02/ft_ultimate_range.c" #include "ex03/ft_strjoin.c" /*#include "ex04/ft_strdup.c"*/ -/*#include "ex05/ft_strdup.c"*/ +#include "ex05/ft_split.c" int main() { @@ -48,14 +48,21 @@ int main() printf("\n "); printf("---------------\n"); - char *strs[] = {"bonjour", "je", "suis", "charle"}; + char *strs[] = {"bon", "je", "suis", "charles"}; char *sep = ", "; int size = 4; char *join; - /*printf("%d\n", cummulative_strlen(size, strs));*/ join = ft_strjoin(size, strs, sep); - printf("%s\n", join); + printf("[%d] %s\n", my_strlen(join), join); + /*for (int i = 0; i < my_strlen(join) + 1; i++)*/ + /*printf("%d ", join[i]);*/ free(join); + printf("\n---------------\n"); + char *str = "bon,je,suis,charles"; + char *charset = ","; + char **sstrs = ft_split(str, charset); + free(sstrs); + return 0; } |
