corrrection erreur dans le split
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -52,6 +52,7 @@ Mkfile.old
|
||||
dkms.conf
|
||||
|
||||
# OS generated files #
|
||||
*.swp
|
||||
.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> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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])
|
||||
|
||||
Reference in New Issue
Block a user