summaryrefslogtreecommitdiffstats
path: root/libft/src/ft_split.c
diff options
context:
space:
mode:
Diffstat (limited to 'libft/src/ft_split.c')
-rw-r--r--libft/src/ft_split.c27
1 files changed, 11 insertions, 16 deletions
diff --git a/libft/src/ft_split.c b/libft/src/ft_split.c
index 34cd57a..a5e1189 100644
--- a/libft/src/ft_split.c
+++ b/libft/src/ft_split.c
@@ -15,8 +15,7 @@
#include <stdlib.h>
#include <inttypes.h>
-static size_t
- ft_count_words(const char *s, char c)
+static size_t ft_count_words(const char *s, char c)
{
size_t i;
size_t count;
@@ -41,8 +40,7 @@ static size_t
return (count);
}
-static size_t
- ft_splitlen(const char *str, char c)
+static size_t ft_splitlen(const char *str, char c)
{
size_t i;
@@ -52,8 +50,7 @@ static size_t
return (i);
}
-static char
- *ft_splitdup(const char *str, char c)
+static char *ft_splitdup(const char *str, char c)
{
char *word;
size_t i;
@@ -70,8 +67,7 @@ static char
return (word);
}
-static char
- **ft_splitfree(char **best_split, size_t j)
+static char **ft_splitfree(char **best_split, size_t j)
{
while (j > 0)
{
@@ -82,8 +78,7 @@ static char
return (NULL);
}
-char
- **ft_split(const char *s, char c)
+char **ft_split(const char *s, char c)
{
char **best_split;
size_t i;
@@ -91,16 +86,16 @@ char
i = 0;
j = 0;
- if (!(best_split = (char **)malloc((ft_count_words(s, c) + 1)
- * sizeof(char *))))
+ if ((best_split = (char **)malloc((ft_count_words(s, c) + 1)
+ * sizeof(char *))) == NULL)
return (NULL);
- while (s[i])
+ while (s[i] != '\0')
{
- while (s[i] == c && s[i])
+ while (s[i] == c && s[i] != '\0')
i++;
- while (s[i] != c && s[i])
+ while (s[i] != c && s[i] != '\0')
{
- if (!(best_split[j] = ft_splitdup(s + i, c)))
+ if ((best_split[j] = ft_splitdup(s + i, c)) == NULL)
return (ft_splitfree(best_split, j));
i += ft_splitlen(s + i, c);
j++;