ft_strtok

This commit is contained in:
whaffman 2025-05-23 15:47:09 +02:00
parent 6c1aafa436
commit c6105a859f
3 changed files with 47 additions and 3 deletions

View File

@ -6,7 +6,7 @@
# By: whaffman <whaffman@student.codam.nl> +#+ #
# +#+ #
# 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

View File

@ -6,7 +6,7 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* 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

42
src/string/ft_strtok.c Normal file
View File

@ -0,0 +1,42 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* ft_strtok.c :+: :+: */
/* +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* 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);
}