ft_count_words
This commit is contained in:
parent
85580c0405
commit
3e469787f9
@ -25,6 +25,7 @@ int ft_isdigit(int c);
|
|||||||
int ft_isalnum(int c);
|
int ft_isalnum(int c);
|
||||||
int ft_isascii(int c);
|
int ft_isascii(int c);
|
||||||
int ft_isprint(int c);
|
int ft_isprint(int c);
|
||||||
|
int ft_count_words(char const *s, char c);
|
||||||
size_t ft_strlen(const char *s);
|
size_t ft_strlen(const char *s);
|
||||||
void *ft_memset(void *s, int c, size_t n);
|
void *ft_memset(void *s, int c, size_t n);
|
||||||
void ft_bzero(void *s, size_t n);
|
void ft_bzero(void *s, size_t n);
|
||||||
|
|||||||
@ -11,10 +11,9 @@
|
|||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
|
||||||
#include "libft.h"
|
#include "libft.h"
|
||||||
|
|
||||||
static int count_words(char const *s, char c)
|
int ft_count_words(char const *s, char c)
|
||||||
{
|
{
|
||||||
int n;
|
int n;
|
||||||
int i;
|
int i;
|
||||||
@ -42,7 +41,7 @@ static void *free_arr(int n, char ***arr)
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief ft_split() splits an array based on a seperator.
|
* @brief ft_split() splits an array based on a seperator.
|
||||||
*
|
*
|
||||||
* @param s is a string.
|
* @param s is a string.
|
||||||
* @param c is the seperator.
|
* @param c is the seperator.
|
||||||
* @return char** an array of string where the last element is NULL.
|
* @return char** an array of string where the last element is NULL.
|
||||||
@ -54,7 +53,7 @@ char **ft_split(char const *s, char c)
|
|||||||
int i;
|
int i;
|
||||||
int j;
|
int j;
|
||||||
|
|
||||||
result = malloc((count_words(s, c) + 1) * sizeof(char *));
|
result = malloc((ft_count_words(s, c) + 1) * sizeof(char *));
|
||||||
if (!result)
|
if (!result)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
i = 0;
|
i = 0;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user