aboutsummaryrefslogtreecommitdiff
path: root/c07/ex05
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2019-07-10 06:41:44 +0200
committerCharles <sircharlesaze@gmail.com>2019-07-10 06:41:44 +0200
commitc2bf9fcefbb4453cee271ccd1af9674ad2f3a181 (patch)
tree9c8ea6e70b228ca843d6a15d78d032d215413c4a /c07/ex05
parente0b1620a22c5fcd673ab78c4d8ce2c649a2cc2fc (diff)
downloadpiscine-c2bf9fcefbb4453cee271ccd1af9674ad2f3a181.tar.gz
piscine-c2bf9fcefbb4453cee271ccd1af9674ad2f3a181.tar.bz2
piscine-c2bf9fcefbb4453cee271ccd1af9674ad2f3a181.zip
c12 start
Diffstat (limited to 'c07/ex05')
-rw-r--r--c07/ex05/ft_split.c55
1 files changed, 35 insertions, 20 deletions
diff --git a/c07/ex05/ft_split.c b/c07/ex05/ft_split.c
index da2d7fc..956782f 100644
--- a/c07/ex05/ft_split.c
+++ b/c07/ex05/ft_split.c
@@ -6,44 +6,59 @@
/* 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 */
+/* Updated: 2019/07/09 12:42:21 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
+int in_charset(char character, char *charset)
+{
+ while (*charset)
+ if (character == *charset++)
+ return (1);
+ return (0);
+}
+
int count_segment(char *str, char *charset)
{
int counter;
- int i;
- counter = 0;
+ counter = 1;
while (*str)
{
- i = 0;
- while (charset[i])
- if (str++ == charset[i++])
- counter++;
+ if (in_charset(*str, charset))
+ counter++;
str++;
}
return (counter);
}
-int strlen_until_sep(char *str, char *charset)
-{
-
-}
-
-char **ft_split(char *str, char *charset)
+char **ft_split(char *str, char *charset)
{
- char **strs;
+ char **strs;
+ char *tmp;
+ int i;
+ int j;
+ int k;
- strs = (char**)malloc(sizeof(char*) * count_segment(str, charset));
+ strs = (char**)malloc(sizeof(char*) * (count_segment(str, charset) + 1));
printf("%d\n", count_segment(str, charset));
- /*while (*str)*/
- /*{*/
-
- /*str++;*/
- /*}*/
+ k = 0;
+ while (*str)
+ {
+ i = 0;
+ while (!in_charset(str[i], charset))
+ i++;
+ tmp = (char*)malloc(sizeof(char) * i);
+ if (tmp == NULL)
+ printf("bonjour");
+ i = 0;
+ while (!in_charset(*str, charset))
+ tmp[i++] = *str++;
+ strs[k++] = tmp;
+ str++;
+ }
+ strs[k] = 0;
return (strs);
}