Libft
Custom implementation of core libc functions with additional utility helpers.
Loading...
Searching...
No Matches
str_split.c File Reference
#include "libft.h"
#include <stdlib.h>
Include dependency graph for str_split.c:

Functions

static char * get_word (char const *s, char sep)
 Extracts a word from a string until the separator.
 
char ** str_split (char const *s, char c)
 Splits a string into an array of strings using a delimiter.
 
size_t str_count_words (char const *s, char sep)
 Counts words in a string separated by a delimiter.
 
void str_array_free (char ***tab_ptr)
 Frees all strings in a null-terminated array and the tab itself.
 

Function Documentation

◆ get_word()

static char * get_word ( char const *  s,
char  sep 
)
static

Extracts a word from a string until the separator.

Parameters
sString to extract from.
sepDelimiter character.
Returns
Newly allocated word, or NULL on failure.
Note
Caller is responsible for freeing the returned string.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ str_array_free()

void str_array_free ( char ***  tab_ptr)

Frees all strings in a null-terminated array and the tab itself.

Note
The tab is set at NULL after beeing freed.
Parameters
tabArray of strings to free.
Here is the caller graph for this function:

◆ str_count_words()

size_t str_count_words ( char const *  s,
char  sep 
)

Counts words in a string separated by a delimiter.

Parameters
sString to analyze.
sepDelimiter character.
Returns
Number of words.
Here is the caller graph for this function: