diff --git a/Makefile b/Makefile index 00d71a0..7954086 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: whaffman +#+ # # +#+ # # Created: 2024/10/10 16:44:36 by whaffman #+# #+# # -# Updated: 2025/02/22 22:20:46 by willem ######## odam.nl # +# Updated: 2025/05/23 13:58:21 by whaffman ######## odam.nl # # # # **************************************************************************** # @@ -36,7 +36,7 @@ SRC_STRING = ft_isalnum.c ft_isalpha.c ft_isascii.c ft_isdigit.c ft_isprint.c \ ft_split.c ft_strchr.c ft_strdup.c ft_striteri.c ft_strjoin.c \ ft_strlcat.c ft_strlcpy.c ft_strlen.c ft_strmapi.c ft_strncmp.c \ ft_strnstr.c ft_strrchr.c ft_strtrim.c ft_substr.c ft_strcmp.c \ - ft_count_words.c ft_isspace.c ft_isdigit_str.c + ft_count_words.c ft_isspace.c ft_isdigit_str.c ft_strtok.c SRC_LIST = ft_lstadd_back.c ft_lstadd_front.c ft_lstclear.c ft_lstdelone.c \ ft_lstiter.c ft_lstlast.c ft_lstmap.c ft_lstnew.c ft_lstsize.c diff --git a/inc/libft.h b/inc/libft.h index 57022cd..0b3f00e 100644 --- a/inc/libft.h +++ b/inc/libft.h @@ -6,7 +6,7 @@ /* By: whaffman +#+ */ /* +#+ */ /* Created: 2024/07/06 11:15:10 by whaffman #+# #+# */ -/* Updated: 2025/02/20 15:43:33 by whaffman ######## odam.nl */ +/* Updated: 2025/05/23 13:59:31 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -92,4 +92,6 @@ int ft_printf(const char *format, ...); char *get_next_line(int fd); +char *ft_strtok(char *str, const char *delim); + #endif diff --git a/src/string/ft_strtok.c b/src/string/ft_strtok.c new file mode 100644 index 0000000..609eb1e --- /dev/null +++ b/src/string/ft_strtok.c @@ -0,0 +1,42 @@ +/* ************************************************************************** */ +/* */ +/* :::::::: */ +/* ft_strtok.c :+: :+: */ +/* +:+ */ +/* By: whaffman +#+ */ +/* +#+ */ +/* Created: 2025/05/23 12:52:46 by whaffman #+# #+# */ +/* Updated: 2025/05/23 14:07:39 by whaffman ######## odam.nl */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strtok(char *str, const char *delim) +{ + static char *next; + char *start; + size_t length; + + if (str) + next = str; + if (!next) + return (NULL); + while (*next && ft_strchr(delim, *next)) + next++; + start = next; + if (!*next) + return (NULL); + length = 0; + while (next[length] && !ft_strchr(delim, next[length])) + length++; + if (next[length]) + { + next[length] = '\0'; + next += length + 1; + } + else + next += length; + ft_printf("next: %s\n", next); + return (start); +}