corrrection erreur dans le split

This commit is contained in:
Hugo LAMY
2019-11-27 21:41:19 +01:00
parent 7c97628f5c
commit feede2804f
4 changed files with 20 additions and 17 deletions

Binary file not shown.

Binary file not shown.

View File

@@ -6,7 +6,7 @@
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/25 14:00:13 by hulamy #+# #+# */
/* Updated: 2019/11/27 20:47:35 by hulamy ### ########.fr */
/* Updated: 2019/11/27 21:35:21 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
@@ -47,8 +47,8 @@
**
** char **ft_split(char const *s, char c);
**
** //int main(int ac, char **av)
** int main(void)
** int main(int ac, char **av)
** //int main(void)
** {
** char **str;
** int i;
@@ -56,17 +56,17 @@
** char *s;
** char c;
**
** // if (ac == 3)
** // {
** if (ac == 3)
** {
** i = 0;
** // s = av[1];
** s = "lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. Suspendisse";
** // c = av[2][0];
** c = ' ';
** s = av[1];
** // s = "lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. Suspendisse";
** c = av[2][0];
** // c = ' ';
** str = ft_split(s, c);
** while (str[i])
** printf("%s\n", str[i++]);
** // }
** }
** return (0);
** }
*/
@@ -76,20 +76,22 @@
static int ft_count_word(char const *s, char c)
{
int i;
int len;
int words;
i = -1;
len = 0;
while (s[++i])
i = 0;
words = 0;
while (s[i])
{
if (s[i] != c)
{
len++;
words++;
while (s[i] && s[i] != c)
i++;
}
else
i++;
}
return (len);
return (words);
}
char **ft_split(char const *s, char c)
@@ -102,7 +104,7 @@ char **ft_split(char const *s, char c)
i = -1;
j = 0;
if (!s || !c)
return (0);
return (NULL);
if (!(array = (char **)malloc(sizeof(char *) * (ft_count_word(s, c) + 1))))
return (NULL);
while (s[++i])