corrrection erreur dans le split
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -52,6 +52,7 @@ Mkfile.old
|
|||||||
dkms.conf
|
dkms.conf
|
||||||
|
|
||||||
# OS generated files #
|
# OS generated files #
|
||||||
|
*.swp
|
||||||
.DS_Store
|
.DS_Store
|
||||||
.DS_Store?
|
.DS_Store?
|
||||||
._*
|
._*
|
||||||
|
|||||||
Binary file not shown.
BIN
srcs/part2/a.out
BIN
srcs/part2/a.out
Binary file not shown.
@@ -6,7 +6,7 @@
|
|||||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/11/25 14:00:13 by hulamy #+# #+# */
|
/* 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);
|
** char **ft_split(char const *s, char c);
|
||||||
**
|
**
|
||||||
** //int main(int ac, char **av)
|
** int main(int ac, char **av)
|
||||||
** int main(void)
|
** //int main(void)
|
||||||
** {
|
** {
|
||||||
** char **str;
|
** char **str;
|
||||||
** int i;
|
** int i;
|
||||||
@@ -56,17 +56,17 @@
|
|||||||
** char *s;
|
** char *s;
|
||||||
** char c;
|
** char c;
|
||||||
**
|
**
|
||||||
** // if (ac == 3)
|
** if (ac == 3)
|
||||||
** // {
|
** {
|
||||||
** i = 0;
|
** i = 0;
|
||||||
** // s = av[1];
|
** s = av[1];
|
||||||
** s = "lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. Suspendisse";
|
** // s = "lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. Suspendisse";
|
||||||
** // c = av[2][0];
|
** c = av[2][0];
|
||||||
** c = ' ';
|
** // c = ' ';
|
||||||
** str = ft_split(s, c);
|
** str = ft_split(s, c);
|
||||||
** while (str[i])
|
** while (str[i])
|
||||||
** printf("%s\n", str[i++]);
|
** printf("%s\n", str[i++]);
|
||||||
** // }
|
** }
|
||||||
** return (0);
|
** return (0);
|
||||||
** }
|
** }
|
||||||
*/
|
*/
|
||||||
@@ -76,20 +76,22 @@
|
|||||||
static int ft_count_word(char const *s, char c)
|
static int ft_count_word(char const *s, char c)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int len;
|
int words;
|
||||||
|
|
||||||
i = -1;
|
i = 0;
|
||||||
len = 0;
|
words = 0;
|
||||||
while (s[++i])
|
while (s[i])
|
||||||
{
|
{
|
||||||
if (s[i] != c)
|
if (s[i] != c)
|
||||||
{
|
{
|
||||||
len++;
|
words++;
|
||||||
while (s[i] && s[i] != c)
|
while (s[i] && s[i] != c)
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
return (len);
|
return (words);
|
||||||
}
|
}
|
||||||
|
|
||||||
char **ft_split(char const *s, char c)
|
char **ft_split(char const *s, char c)
|
||||||
@@ -102,7 +104,7 @@ char **ft_split(char const *s, char c)
|
|||||||
i = -1;
|
i = -1;
|
||||||
j = 0;
|
j = 0;
|
||||||
if (!s || !c)
|
if (!s || !c)
|
||||||
return (0);
|
return (NULL);
|
||||||
if (!(array = (char **)malloc(sizeof(char *) * (ft_count_word(s, c) + 1))))
|
if (!(array = (char **)malloc(sizeof(char *) * (ft_count_word(s, c) + 1))))
|
||||||
return (NULL);
|
return (NULL);
|
||||||
while (s[++i])
|
while (s[++i])
|
||||||
|
|||||||
Reference in New Issue
Block a user