/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_split.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: cchauvet int ft_strstr(char *str, char *to_find) { unsigned int i; unsigned int j; i = 0; while (str[i] != 0) { j = 0; while (str[i + j] == to_find[j]) { if (to_find[j + 1] == 0) return (i); j++; } i++; } return (i); } int ft_strlen(char *str) { int i; i = 0; while (str[i] != 0) i++; return (i); } char **ft_split(char *str, char *sep) { char **tab; int i; int j; int k; i = 0; j = 0; tab = malloc(sizeof(*str) * ft_strlen(str)); while (str[i] != 0 && ft_strlen(str) > i) { k = i; tab[j] = malloc(sizeof(**tab) * (i - k + ft_strstr(&str[i], sep) + 1)); while (i < k + ft_strstr(&str[k], sep)) { tab[j][i - k] = str[i]; i++; } tab[j][i - k] = '\0'; i = k + ft_strstr(&str[k], sep) + ft_strlen(sep); j++; } tab[j] = malloc(sizeof(char)); tab[j] = ""; return (tab); }