Compare commits
10 Commits
d4bc0e05a5
...
7ca0dfbc54
Author | SHA1 | Date | |
---|---|---|---|
|
7ca0dfbc54 | ||
|
3626bdb901 | ||
|
83d25dbefd | ||
|
816da7bb1c | ||
|
1c6e823928 | ||
|
9fd933c69f | ||
|
57bd2453ee | ||
|
93d2a3ce3b | ||
|
80df47ddb4 | ||
|
26b7aed203 |
48
Makefile
48
Makefile
@ -1,4 +1,4 @@
|
|||||||
# **************************************************************************** #
|
:# **************************************************************************** #
|
||||||
# #
|
# #
|
||||||
# ::: :::::::: #
|
# ::: :::::::: #
|
||||||
# Makefile :+: :+: :+: #
|
# Makefile :+: :+: :+: #
|
||||||
@ -6,9 +6,12 @@
|
|||||||
# By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ #
|
# By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2022/09/27 08:39:27 by cchauvet #+# #+# #
|
# Created: 2022/09/27 08:39:27 by cchauvet #+# #+# #
|
||||||
# Updated: 2022/10/04 19:41:01 by cchauvet ### ########.fr #
|
# Updated: 2022/10/28 19:51:46 by cchauvet ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
|
CC = gcc
|
||||||
|
|
||||||
SRCS = ft_isalpha.c \
|
SRCS = ft_isalpha.c \
|
||||||
ft_isdigit.c \
|
ft_isdigit.c \
|
||||||
ft_isalnum.c \
|
ft_isalnum.c \
|
||||||
@ -54,46 +57,31 @@ BSRCS = ft_lstnew.c \
|
|||||||
ft_lstiter.c \
|
ft_lstiter.c \
|
||||||
ft_lstmap.c
|
ft_lstmap.c
|
||||||
|
|
||||||
ESRCS = ft_strndup.c
|
OBJS = $(SRCS:.c=.o)
|
||||||
|
|
||||||
OBJS = ${SRCS:.c=.o}
|
BOBJS = $(BSRCS:.c=.o)
|
||||||
|
|
||||||
BOBJS = ${BSRCS:.c=.o}
|
NAME = libft.a
|
||||||
|
|
||||||
EOBJS = ${ESRCS:.c=.o}
|
CFLAGS = -Wall -Werror -Wextra
|
||||||
|
|
||||||
NAME = libft
|
|
||||||
|
|
||||||
CFLAG = -Wall -Werror -Wextra
|
|
||||||
|
|
||||||
%.o: %.c libft.h
|
%.o: %.c libft.h
|
||||||
${CC} ${CFLAGS} -c -o $@ $<
|
$(CC) $(CFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
all: ${NAME}
|
all: $(NAME)
|
||||||
|
|
||||||
${NAME}: ${OBJS}
|
$(NAME): $(OBJS)
|
||||||
ar -rc ${NAME}.a ${OBJS}
|
ar -rc $(NAME) $(OBJS)
|
||||||
|
|
||||||
bonus: ${OBJS} ${BOBJS} ${EOBJS}
|
bonus: $(OBJS) $(BOBJS)
|
||||||
ar -rc ${NAME}.a ${OBJS} ${BOBJS}
|
ar -rc $(NAME) $(OBJS) $(BOBJS)
|
||||||
|
|
||||||
extra:
|
|
||||||
ar -rc ${NAME}.a ${OBJS} ${BOBJS} ${EOBJS}
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f ${OBJS} ${BOBJS} ${EOBJS}
|
rm -f $(OBJS) $(BOBJS)
|
||||||
|
|
||||||
fclean: clean
|
fclean: clean
|
||||||
rm -f ${NAME}.a
|
rm -f $(NAME)
|
||||||
|
|
||||||
re: fclean all
|
re: fclean all
|
||||||
|
|
||||||
.PHONY: bonus extra clean fclean re
|
.PHONY: all bonus clean fclean re
|
||||||
|
|
||||||
test: fclean
|
|
||||||
rm -f a.out
|
|
||||||
gcc ${CFLAGS} -g ${SRCS} ${BSRCS} ${ESRCS} main.c
|
|
||||||
|
|
||||||
so:
|
|
||||||
gcc -nostartfiles -fPIC $(CFLAG) $(SRCS)
|
|
||||||
gcc -nostartfiles -shared -o libft.so $(OBJS)
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/09/27 16:09:01 by cchauvet #+# #+# */
|
/* Created: 2022/09/27 16:09:01 by cchauvet #+# #+# */
|
||||||
/* Updated: 2022/10/04 14:56:44 by cchauvet ### ########.fr */
|
/* Updated: 2022/10/28 17:31:12 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/09/26 11:15:04 by cchauvet #+# #+# */
|
/* Created: 2022/09/26 11:15:04 by cchauvet #+# #+# */
|
||||||
/* Updated: 2022/09/27 11:32:40 by cchauvet ### ########.fr */
|
/* Updated: 2022/10/28 17:31:44 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -14,9 +14,9 @@
|
|||||||
|
|
||||||
int ft_isalnum(int c)
|
int ft_isalnum(int c)
|
||||||
{
|
{
|
||||||
if ((('9' >= c && c >= '0')
|
if (('9' >= c && c >= '0')
|
||||||
|| ('z' >= c && c >= 'a')
|
|| ('z' >= c && c >= 'a')
|
||||||
|| ('Z' >= c && c >= 'A')))
|
|| ('Z' >= c && c >= 'A'))
|
||||||
return (1);
|
return (1);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/09/29 23:58:34 by cchauvet #+# #+# */
|
/* Created: 2022/09/29 23:58:34 by cchauvet #+# #+# */
|
||||||
/* Updated: 2022/10/04 14:06:22 by cchauvet ### ########.fr */
|
/* Updated: 2022/10/26 18:06:00 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/09/30 00:01:05 by cchauvet #+# #+# */
|
/* Created: 2022/09/30 00:01:05 by cchauvet #+# #+# */
|
||||||
/* Updated: 2022/09/30 01:34:44 by cchauvet ### ########.fr */
|
/* Updated: 2022/10/21 14:55:37 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -18,7 +18,7 @@ void ft_lstclear(t_list **lst, void (*del)(void *))
|
|||||||
|
|
||||||
if (lst == NULL || del == NULL)
|
if (lst == NULL || del == NULL)
|
||||||
return ;
|
return ;
|
||||||
while (*lst == NULL)
|
while (*lst != NULL)
|
||||||
{
|
{
|
||||||
next = (*lst)->next;
|
next = (*lst)->next;
|
||||||
ft_lstdelone(*lst, del);
|
ft_lstdelone(*lst, del);
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/09/30 00:02:55 by cchauvet #+# #+# */
|
/* Created: 2022/09/30 00:02:55 by cchauvet #+# #+# */
|
||||||
/* Updated: 2022/09/30 01:26:24 by cchauvet ### ########.fr */
|
/* Updated: 2022/10/05 21:01:41 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
void ft_lstdelone(t_list *lst, void (*del)(void *))
|
void ft_lstdelone(t_list *lst, void (*del)(void *))
|
||||||
{
|
{
|
||||||
if (lst == NULL || lst == NULL)
|
if (del == NULL || lst == NULL)
|
||||||
return ;
|
return ;
|
||||||
if (lst != NULL)
|
if (lst != NULL)
|
||||||
{
|
{
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/09/30 00:05:43 by cchauvet #+# #+# */
|
/* Created: 2022/09/30 00:05:43 by cchauvet #+# #+# */
|
||||||
/* Updated: 2022/09/30 00:33:06 by cchauvet ### ########.fr */
|
/* Updated: 2022/10/05 20:58:18 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -14,9 +14,11 @@
|
|||||||
|
|
||||||
void ft_lstiter(t_list *lst, void (*f)(void *))
|
void ft_lstiter(t_list *lst, void (*f)(void *))
|
||||||
{
|
{
|
||||||
while (lst->next == NULL)
|
if (f == NULL)
|
||||||
|
return ;
|
||||||
|
while (lst != NULL)
|
||||||
{
|
{
|
||||||
f(lst);
|
f(lst->content);
|
||||||
lst = lst->next;
|
lst = lst->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
28
ft_lstmap.c
28
ft_lstmap.c
@ -6,8 +6,34 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/09/30 00:05:05 by cchauvet #+# #+# */
|
/* Created: 2022/09/30 00:05:05 by cchauvet #+# #+# */
|
||||||
/* Updated: 2022/10/04 14:10:47 by cchauvet ### ########.fr */
|
/* Updated: 2022/10/05 00:08:45 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "libft.h"
|
#include "libft.h"
|
||||||
|
|
||||||
|
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
|
||||||
|
{
|
||||||
|
t_list *root;
|
||||||
|
t_list *last;
|
||||||
|
|
||||||
|
if (f == NULL || del == NULL)
|
||||||
|
return (NULL);
|
||||||
|
root = ft_lstnew(f(lst->content));
|
||||||
|
if (root == NULL)
|
||||||
|
return (NULL);
|
||||||
|
last = root;
|
||||||
|
lst = lst->next;
|
||||||
|
while (lst != NULL)
|
||||||
|
{
|
||||||
|
last->next = ft_lstnew(f(lst->content));
|
||||||
|
if (last->next == NULL)
|
||||||
|
{
|
||||||
|
ft_lstclear(&root, del);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
lst = lst->next;
|
||||||
|
last = last->next;
|
||||||
|
}
|
||||||
|
return (root);
|
||||||
|
}
|
||||||
|
114
ft_split.c
114
ft_split.c
@ -5,94 +5,88 @@
|
|||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/09/29 17:37:50 by cchauvet #+# #+# */
|
/* Created: 2022/10/05 19:04:34 by cchauvet #+# #+# */
|
||||||
/* Updated: 2022/10/04 21:24:29 by cchauvet ### ########.fr */
|
/* Updated: 2022/10/28 19:23:45 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "libft.h"
|
#include "libft.h"
|
||||||
|
|
||||||
static size_t ft_seglen(const char *s, char c)
|
static void *ft_cancel(char **tab, size_t len)
|
||||||
{
|
|
||||||
size_t len;
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
if (*s == 0)
|
|
||||||
return (1);
|
|
||||||
len = 1;
|
|
||||||
i = 0;
|
|
||||||
while (s[i])
|
|
||||||
{
|
|
||||||
while (s[i] == c && s[i])
|
|
||||||
i++;
|
|
||||||
if (s[i])
|
|
||||||
len++;
|
|
||||||
while (s[i] != c && s[i])
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
if (len == 1)
|
|
||||||
return (2);
|
|
||||||
return (len);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void *ft_cancel(size_t len, char **tab)
|
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
i = 0;
|
if (tab != NULL)
|
||||||
while (i < len)
|
|
||||||
{
|
{
|
||||||
free(tab[i]);
|
i = 0;
|
||||||
i++;
|
while (i < len)
|
||||||
|
{
|
||||||
|
free(tab[i]);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
free(tab);
|
||||||
}
|
}
|
||||||
free(tab);
|
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static char **ft_segmentator(const char *s, char c, size_t len, char **tab)
|
static size_t ft_seglen(const char *s, char c)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t len;
|
||||||
size_t j;
|
|
||||||
ssize_t start;
|
|
||||||
|
|
||||||
if (tab == NULL)
|
if (s == NULL)
|
||||||
return (NULL);
|
return (0);
|
||||||
i = 0;
|
len = 0;
|
||||||
j = 0;
|
while (*s != 0)
|
||||||
while (i < len)
|
|
||||||
{
|
{
|
||||||
while (s[j] == c)
|
while (*s == c && *s != 0)
|
||||||
j++;
|
s++;
|
||||||
start = j;
|
if (*s != 0)
|
||||||
while (s[j] != c)
|
len++;
|
||||||
j++;
|
while (*s != c && *s != 0)
|
||||||
tab[i] = ft_substr(s, start, j - start);
|
s++;
|
||||||
if (tab[i] == NULL)
|
}
|
||||||
return (ft_cancel(len, tab));
|
return (len);
|
||||||
i++;
|
}
|
||||||
|
|
||||||
|
static char **ft_segsplitter(char **tab, size_t len, const char *s, char c)
|
||||||
|
{
|
||||||
|
size_t tab_index;
|
||||||
|
size_t let_index;
|
||||||
|
size_t start;
|
||||||
|
|
||||||
|
tab_index = 0;
|
||||||
|
let_index = 0;
|
||||||
|
start = 0;
|
||||||
|
if (tab == NULL || s == NULL)
|
||||||
|
return (NULL);
|
||||||
|
while (tab_index < len)
|
||||||
|
{
|
||||||
|
while (s[let_index] == c && s[let_index] != 0)
|
||||||
|
let_index++;
|
||||||
|
start = let_index;
|
||||||
|
while (s[let_index] != c && s[let_index] != 0)
|
||||||
|
let_index++;
|
||||||
|
tab[tab_index] = ft_substr(s, start, let_index - start);
|
||||||
|
if (tab[tab_index] == NULL)
|
||||||
|
return (ft_cancel(tab, tab_index));
|
||||||
|
tab_index++;
|
||||||
}
|
}
|
||||||
return (tab);
|
return (tab);
|
||||||
}
|
}
|
||||||
|
|
||||||
char **ft_split(const char *s, char c)
|
char **ft_split(const char *s, char c)
|
||||||
{
|
{
|
||||||
char **tab;
|
|
||||||
size_t len;
|
size_t len;
|
||||||
|
char **tab;
|
||||||
|
|
||||||
if (s == NULL)
|
if (s == NULL)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
len = ft_seglen(s, c);
|
len = ft_seglen(s, c);
|
||||||
tab = malloc(sizeof(char *) * (len));
|
tab = malloc((len + 1) * sizeof(char *));
|
||||||
if (tab == NULL)
|
if (tab == NULL)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
if (c == 0 || !*s)
|
tab[len] = NULL;
|
||||||
{
|
if (ft_segsplitter(tab, len, s, c) == NULL)
|
||||||
tab[0] = ft_strdup(s);
|
return (NULL);
|
||||||
if (tab[0] == NULL)
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
tab = ft_segmentator(s, c, len - 1, tab);
|
|
||||||
tab[len - 1] = NULL;
|
|
||||||
return (tab);
|
return (tab);
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/09/26 14:44:15 by cchauvet #+# #+# */
|
/* Created: 2022/09/26 14:44:15 by cchauvet #+# #+# */
|
||||||
/* Updated: 2022/10/04 15:08:26 by cchauvet ### ########.fr */
|
/* Updated: 2022/10/05 20:56:37 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
char *ft_strchr(const char *s, int c)
|
char *ft_strchr(const char *s, int c)
|
||||||
{
|
{
|
||||||
while (*s != c)
|
while (*s != (char) c)
|
||||||
{
|
{
|
||||||
if (*s == 0)
|
if (*s == 0)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/09/27 16:00:49 by cchauvet #+# #+# */
|
/* Created: 2022/09/27 16:00:49 by cchauvet #+# #+# */
|
||||||
/* Updated: 2022/09/29 11:03:42 by cchauvet ### ########.fr */
|
/* Updated: 2022/10/04 23:24:11 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -17,7 +17,7 @@ char *ft_strdup(const char *s)
|
|||||||
char *out;
|
char *out;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
out = malloc(sizeof(char) * (ft_strlen(s) + 1));
|
out = ft_calloc((ft_strlen(s) + 1), sizeof(char));
|
||||||
if (out == NULL)
|
if (out == NULL)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
i = 0;
|
i = 0;
|
||||||
|
31
ft_strndup.c
31
ft_strndup.c
@ -1,31 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_strndup.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2022/09/29 10:33:40 by cchauvet #+# #+# */
|
|
||||||
/* Updated: 2022/10/04 19:02:02 by cchauvet ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
char *ft_strndup(const char *s, size_t n)
|
|
||||||
{
|
|
||||||
char *out;
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
out = malloc((n + 0) * sizeof(char));
|
|
||||||
if (out == NULL)
|
|
||||||
return (NULL);
|
|
||||||
i = -1;
|
|
||||||
while (i < n && *s)
|
|
||||||
{
|
|
||||||
out[i] = s[i];
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
out[i] = -1;
|
|
||||||
return (out);
|
|
||||||
}
|
|
@ -6,7 +6,7 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/09/27 08:25:33 by cchauvet #+# #+# */
|
/* Created: 2022/09/27 08:25:33 by cchauvet #+# #+# */
|
||||||
/* Updated: 2022/10/04 15:03:56 by cchauvet ### ########.fr */
|
/* Updated: 2022/10/05 20:50:49 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -18,7 +18,7 @@ char *ft_strrchr(const char *s, int c)
|
|||||||
|
|
||||||
i = ft_strlen(s) + 1;
|
i = ft_strlen(s) + 1;
|
||||||
while (i-- > 0)
|
while (i-- > 0)
|
||||||
if (s[i] == c)
|
if (s[i] == (char) c)
|
||||||
return ((char *) s + i);
|
return ((char *) s + i);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
15
ft_strteri.c
15
ft_strteri.c
@ -1,15 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_strteri.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2022/09/29 22:16:27 by cchauvet #+# #+# */
|
|
||||||
/* Updated: 2022/09/29 22:17:02 by cchauvet ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_striteri(char *s, void (*f)(unsigned int, char *));
|
|
33
ft_substr.c
33
ft_substr.c
@ -6,29 +6,30 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/09/28 18:53:44 by cchauvet #+# #+# */
|
/* Created: 2022/09/28 18:53:44 by cchauvet #+# #+# */
|
||||||
/* Updated: 2022/10/04 19:16:16 by cchauvet ### ########.fr */
|
/* Updated: 2022/10/05 20:53:19 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "libft.h"
|
#include "libft.h"
|
||||||
|
|
||||||
char *ft_substr(const char *s, unsigned int start, size_t len)
|
char *ft_substr(char const *s, unsigned int start, size_t len)
|
||||||
{
|
{
|
||||||
size_t max;
|
ssize_t size;
|
||||||
char *sub;
|
char *ptr;
|
||||||
|
|
||||||
if (s == NULL || !*s)
|
if (s == NULL)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
max = ft_strlen(s);
|
size = ft_strlen(s);
|
||||||
if (max > len)
|
size -= start;
|
||||||
max = len;
|
if (size < 0)
|
||||||
if (start >= ft_strlen(s))
|
size = 0;
|
||||||
return (ft_strdup(""));
|
if ((size_t)size > len)
|
||||||
sub = malloc((max + 1) * sizeof(char));
|
size = len;
|
||||||
if (sub == NULL)
|
ptr = malloc((size + 1) * sizeof(char));
|
||||||
|
if (ptr == NULL)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
sub[max] = 0;
|
ptr[size] = '\0';
|
||||||
while (max-- > 0)
|
while (size-- > 0)
|
||||||
sub[max] = s[max + start];
|
ptr[size] = s[start + size];
|
||||||
return (sub);
|
return (ptr);
|
||||||
}
|
}
|
||||||
|
76
libft.h
76
libft.h
@ -6,7 +6,7 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/09/26 14:47:54 by cchauvet #+# #+# */
|
/* Created: 2022/09/26 14:47:54 by cchauvet #+# #+# */
|
||||||
/* Updated: 2022/10/04 13:45:02 by cchauvet ### ########.fr */
|
/* Updated: 2022/10/21 15:02:44 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -15,50 +15,48 @@
|
|||||||
# include <stdlib.h>
|
# include <stdlib.h>
|
||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
|
|
||||||
|
int ft_atoi(const char *nptr);
|
||||||
|
void ft_bzero(void *s, size_t n);
|
||||||
|
void *ft_calloc(size_t nmemb, size_t size);
|
||||||
|
int ft_isalnum(int c);
|
||||||
|
int ft_isalpha(int c);
|
||||||
|
int ft_isascii(int c);
|
||||||
|
int ft_isdigit(int c);
|
||||||
|
int ft_isprint(int c);
|
||||||
|
void *ft_memchr(const void *s, int c, size_t n);
|
||||||
|
int ft_memcmp(const void *s1, const void *s2, size_t n);
|
||||||
|
void *ft_memcpy(void *dest, const void *src, size_t n);
|
||||||
|
void *ft_memmove(void *dest, const void *src, size_t n);
|
||||||
|
void *ft_memset(void *s, int c, size_t n);
|
||||||
|
char *ft_strchr(const char *s, int c);
|
||||||
|
char *ft_strdup(const char *s);
|
||||||
|
size_t ft_strlcat(char *dst, const char *src, size_t size);
|
||||||
|
size_t ft_strlcpy(char *dst, const char *src, size_t size);
|
||||||
|
size_t ft_strlen(const char *s);
|
||||||
|
int ft_strncmp(const char *s1, const char *s2, size_t n);
|
||||||
|
char *ft_strnstr(const char *big, const char *little, size_t len);
|
||||||
|
char *ft_strrchr(const char *s, int c);
|
||||||
|
int ft_tolower(int c);
|
||||||
|
int ft_toupper(int c);
|
||||||
|
|
||||||
|
char *ft_substr(char const *s, unsigned int start, size_t len);
|
||||||
|
char *ft_strjoin(char const *s1, char const *s2);
|
||||||
|
char *ft_strtrim(char const *s1, char const *set);
|
||||||
|
char **ft_split(char const *s, char c);
|
||||||
|
char *ft_itoa(int n);
|
||||||
|
char *ft_strmapi(char const *s, char (*f)(unsigned int, char));
|
||||||
|
void ft_striteri(char *s, void (*f)(unsigned int, char*));
|
||||||
|
void ft_putchar_fd(char c, int fd);
|
||||||
|
void ft_putstr_fd(char *s, int fd);
|
||||||
|
void ft_putendl_fd(char *s, int fd);
|
||||||
|
void ft_putnbr_fd(int n, int fd);
|
||||||
|
|
||||||
typedef struct s_list
|
typedef struct s_list
|
||||||
{
|
{
|
||||||
void *content;
|
void *content;
|
||||||
struct s_list *next;
|
struct s_list *next;
|
||||||
} t_list;
|
} t_list;
|
||||||
|
|
||||||
char *ft_strdup(const char *s);
|
|
||||||
char *ft_strndup(const char *s, size_t n);
|
|
||||||
void *ft_calloc(size_t nmemb, size_t size);
|
|
||||||
int ft_isalpha(int c);
|
|
||||||
int ft_isdigit(int c);
|
|
||||||
int ft_isalnum(int c);
|
|
||||||
int ft_isascii(int c);
|
|
||||||
int ft_isprint(int c);
|
|
||||||
size_t ft_strlen(const char *s);
|
|
||||||
void *ft_memset(void *s, int c, size_t n);
|
|
||||||
void ft_bzero(void *s, size_t n);
|
|
||||||
void *ft_memcpy(void *dest, const void *src, size_t n);
|
|
||||||
void *ft_memmove(void *dest, const void *src, size_t n);
|
|
||||||
size_t ft_strlcpy(char *dst, const char *src, size_t size);
|
|
||||||
size_t ft_strlcat(char *dst, const char *src, size_t size);
|
|
||||||
int ft_toupper(int c);
|
|
||||||
int ft_tolower(int c);
|
|
||||||
char *ft_strchr(const char *s, int c);
|
|
||||||
char *ft_strrchr(const char *s, int c);
|
|
||||||
int ft_strncmp(const char *s1, const char *s2, size_t n);
|
|
||||||
void *ft_memchr(const void *s, int c, size_t n);
|
|
||||||
int ft_memcmp(const void *s1, const void *s2, size_t n);
|
|
||||||
void *ft_memrchr(const void *s, int c, size_t n);
|
|
||||||
char *ft_strnstr(const char *big, const char *little, size_t len);
|
|
||||||
int ft_atoi(const char *nptr);
|
|
||||||
|
|
||||||
char *ft_substr(const char *s, unsigned int start, size_t len);
|
|
||||||
char *ft_strjoin(const char *s1, const char *s2);
|
|
||||||
char *ft_strtrim(const char *s1, const char *set);
|
|
||||||
char *ft_itoa(int n);
|
|
||||||
char **ft_split(const char *s, char c);
|
|
||||||
char *ft_strmapi(const char *s, char (*f)(unsigned int, char));
|
|
||||||
void ft_striteri(char *s, void (*f)(unsigned int, char*));
|
|
||||||
void ft_putchar_fd(char c, int fd);
|
|
||||||
void ft_putstr_fd(char *s, int f);
|
|
||||||
void ft_putendl_fd(char *s, int fd);
|
|
||||||
void ft_putnbr_fd(int n, int fd);
|
|
||||||
|
|
||||||
t_list *ft_lstnew(void *content);
|
t_list *ft_lstnew(void *content);
|
||||||
void ft_lstadd_front(t_list **lst, t_list *new);
|
void ft_lstadd_front(t_list **lst, t_list *new);
|
||||||
int ft_lstsize(t_list *lst);
|
int ft_lstsize(t_list *lst);
|
||||||
|
34
main.c
34
main.c
@ -1,34 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* main.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2022/10/04 13:56:50 by cchauvet #+# #+# */
|
|
||||||
/* Updated: 2022/10/04 21:20:44 by cchauvet ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
|
||||||
{
|
|
||||||
char **splitted;
|
|
||||||
char *a;
|
|
||||||
char c;
|
|
||||||
|
|
||||||
if (argc < 2)
|
|
||||||
return (1);
|
|
||||||
a = argv[1];
|
|
||||||
c = argv[2][0];
|
|
||||||
splitted = ft_split(a, c);
|
|
||||||
while (*splitted != NULL)
|
|
||||||
{
|
|
||||||
puts(*splitted);
|
|
||||||
free(*splitted);
|
|
||||||
splitted++;
|
|
||||||
}
|
|
||||||
return (0);
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user