libft rendu norm fixes and moulitest fixes are here

This commit is contained in:
Jack Halford 2016-11-03 17:57:17 +01:00
parent 26652ca579
commit 8b89d3cd49
53 changed files with 696 additions and 107 deletions

View file

@ -1,13 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isalnum.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:56:18 by jhalford #+# #+# */
/* Updated: 2016/11/03 15:31:33 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h" #include "libft.h"
int ft_isalnum(int c) int ft_isalnum(int c)
{ {
unsigned char a; if ((c >= 'a' && c <= 'z')
|| (c >= 'A' && c <= 'Z')
a = (unsigned char)c; || (c >= '0' && c <= '9'))
if ((a >= 'a' && a <= 'z') return (c);
|| (a >= 'A' && a <= 'Z')
|| (a >= '0' && a <= '9'))
return (a);
return (0); return (0);
} }

View file

@ -1,11 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isalpha.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:56:24 by jhalford #+# #+# */
/* Updated: 2016/11/03 15:32:00 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h" #include "libft.h"
int ft_isalpha(int c) int ft_isalpha(int c)
{ {
unsigned char a; if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
return (c);
a = (unsigned char)c;
if ((a >= 'a' && a <= 'z') || (a >= 'A' && a <= 'Z'))
return (a);
return (0); return (0);
} }

View file

@ -1,11 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isascii.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:56:28 by jhalford #+# #+# */
/* Updated: 2016/11/03 15:35:42 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h" #include "libft.h"
int ft_isascii(int c) int ft_isascii(int c)
{ {
unsigned char a; if (c >= 0 && c <= 127)
return (1);
a = (unsigned char)c;
if (a >= 0 && a <= 127)
return (a);
return (0); return (0);
} }

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isdigit.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:56:33 by jhalford #+# #+# */
/* Updated: 2016/11/03 14:56:34 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h" #include "libft.h"
int ft_isdigit(int c) int ft_isdigit(int c)

View file

@ -1,11 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isprint.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:56:38 by jhalford #+# #+# */
/* Updated: 2016/11/03 15:32:40 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h" #include "libft.h"
int ft_isprint(int c) int ft_isprint(int c)
{ {
unsigned char a; if (c >= 32 && c <= 126)
return (c);
a = (unsigned char)c;
if (a >= 32 && a <= 126)
return (a);
return (0); return (0);
} }

View file

@ -1,11 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_tolower.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:58:46 by jhalford #+# #+# */
/* Updated: 2016/11/03 15:24:09 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h" #include "libft.h"
int ft_toupper(int c) int ft_tolower(int c)
{ {
unsigned char a; if (c >= 'A' && c <= 'Z')
return (c + 32);
a = (unsigned char)c; return (c);
if (a >= 'A' && a <= 'Z')
return (a + 32);
return (a);
} }

View file

@ -1,11 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_toupper.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:53:58 by jhalford #+# #+# */
/* Updated: 2016/11/03 15:24:40 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h" #include "libft.h"
int ft_toupper(int c) int ft_toupper(int c)
{ {
unsigned char a; if (c >= 'a' && c <= 'z')
return (c - 32);
a = (unsigned char)c; return (c);
if (a >= 'a' && a <= 'z')
return (a - 32);
return (a);
} }

22
libft/src/lst/ft_lstadd.c Normal file
View file

@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstadd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:57:13 by jhalford #+# #+# */
/* Updated: 2016/11/03 14:57:13 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstadd(t_list **alst, t_list *new)
{
if (new)
{
new->next = *alst;
*alst = new;
}
}

20
libft/src/lst/ft_lstdel.c Normal file
View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstdel.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 15:18:57 by jhalford #+# #+# */
/* Updated: 2016/11/03 16:40:21 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstdel(t_list **alst, void (*del)(void *, size_t))
{
if ((*alst)->next)
ft_lstdel(&(*alst)->next, del);
ft_lstdelone(&(*alst), del);
}

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstdelone.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:57:15 by jhalford #+# #+# */
/* Updated: 2016/11/03 15:15:51 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h" #include "libft.h"
void ft_lstdelone(t_list **alst, void (*del)(void *, size_t)) void ft_lstdelone(t_list **alst, void (*del)(void *, size_t))

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lsteadd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:57:17 by jhalford #+# #+# */
/* Updated: 2016/11/03 14:57:18 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h" #include "libft.h"
void ft_lsteadd(t_list **alst, t_list *new) void ft_lsteadd(t_list **alst, t_list *new)
@ -5,7 +17,6 @@ void ft_lsteadd(t_list **alst, t_list *new)
t_list *lst; t_list *lst;
lst = *alst; lst = *alst;
new->next = NULL;
if (lst) if (lst)
{ {
while (lst->next) while (lst->next)

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstiter.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:57:19 by jhalford #+# #+# */
/* Updated: 2016/11/03 14:57:19 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h" #include "libft.h"
void ft_lstiter(t_list *lst, void (*f)(t_list *elem)) void ft_lstiter(t_list *lst, void (*f)(t_list *elem))

View file

@ -1,5 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstmap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:57:21 by jhalford #+# #+# */
/* Updated: 2016/11/03 16:40:39 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h" #include "libft.h"
static void ft_lsteadd(t_list **alst, t_list *new)
{
t_list *lst;
lst = *alst;
new->next = NULL;
if (lst)
{
while (lst->next)
lst = lst->next;
lst->next = new;
}
else
*alst = new;
}
t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem)) t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem))
{ {
t_list *out; t_list *out;
@ -9,7 +37,6 @@ t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem))
while (lst) while (lst)
{ {
elem = (*f)(lst); elem = (*f)(lst);
if (elem)
elem = ft_lstnew(elem->content, elem->content_size); elem = ft_lstnew(elem->content, elem->content_size);
ft_lsteadd(&out, elem); ft_lsteadd(&out, elem);
lst = lst->next; lst = lst->next;

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstnew.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:57:24 by jhalford #+# #+# */
/* Updated: 2016/11/03 14:57:24 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h" #include "libft.h"
t_list *ft_lstnew(void const *content, size_t content_size) t_list *ft_lstnew(void const *content, size_t content_size)

View file

@ -1,5 +1,37 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_itoa.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:57:10 by jhalford #+# #+# */
/* Updated: 2016/11/03 15:27:16 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h" #include "libft.h"
static char *ft_strrev(char *str)
{
int len;
char tmp;
int i;
i = 0;
len = 0;
while (str[len] != '\0')
len++;
while (i < len / 2)
{
tmp = str[len - (i + 1)];
str[len - (i + 1)] = str[i];
str[i] = tmp;
i++;
}
return (str);
}
static size_t ft_size(int n) static size_t ft_size(int n)
{ {
size_t i; size_t i;
@ -14,9 +46,11 @@ char *ft_itoa(int n)
{ {
int i; int i;
char *str; char *str;
int neg;
i = 0; i = 0;
str = ft_strnew(ft_size(n) + 1); str = ft_strnew(ft_size(n) + 1);
neg = FT_NEG(n) ? 1 : 0;
if (n == 0) if (n == 0)
{ {
str[i++] = '0'; str[i++] = '0';
@ -28,7 +62,7 @@ char *ft_itoa(int n)
str[i++] = FT_ABS(n % 10) + '0'; str[i++] = FT_ABS(n % 10) + '0';
n /= 10; n /= 10;
} }
if (FT_NEG(n)) if (neg)
str[i++] = '-'; str[i++] = '-';
str[i] = '\0'; str[i] = '\0';
return (ft_strrev(str)); return (ft_strrev(str));

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_bzero.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:56:08 by jhalford #+# #+# */
/* Updated: 2016/11/03 14:56:09 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h" #include "libft.h"
void ft_bzero(void *s, size_t n) void ft_bzero(void *s, size_t n)

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memalloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:57:25 by jhalford #+# #+# */
/* Updated: 2016/11/03 14:57:25 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h" #include "libft.h"
void *ft_memalloc(size_t size) void *ft_memalloc(size_t size)

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memccpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:57:26 by jhalford #+# #+# */
/* Updated: 2016/11/03 15:36:05 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h" #include "libft.h"
void *ft_memccpy(void *dst, const void *src, int c, size_t n) void *ft_memccpy(void *dst, const void *src, int c, size_t n)
@ -8,7 +20,7 @@ void *ft_memccpy(void *dst, const void *src, int c, size_t n)
while (++i < n) while (++i < n)
{ {
*(char *)dst++ = *(char *)src; *(char *)dst++ = *(char *)src;
if (*(char *)src++ == (unsigned char)c) if (*(char *)src++ == c)
return (dst); return (dst);
} }
return (NULL); return (NULL);

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:57:28 by jhalford #+# #+# */
/* Updated: 2016/11/03 14:57:29 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h" #include "libft.h"
void *ft_memchr(const void *s, int c, size_t n) void *ft_memchr(const void *s, int c, size_t n)

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:57:30 by jhalford #+# #+# */
/* Updated: 2016/11/03 15:44:21 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h" #include "libft.h"
int ft_memcmp(const void *s1, const void *s2, size_t n) int ft_memcmp(const void *s1, const void *s2, size_t n)
@ -5,10 +17,10 @@ int ft_memcmp(const void *s1, const void *s2, size_t n)
size_t i; size_t i;
int cmp; int cmp;
i = 0; i = -1;
while (++i < n) while (++i < n)
{ {
cmp = ((unsigned char *)s1)[i] - ((unsigned char *)s2)[i]; cmp = *(unsigned char *)s1++ - *(unsigned char *)s2++;
if (cmp) if (cmp)
return (cmp); return (cmp);
} }

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:57:31 by jhalford #+# #+# */
/* Updated: 2016/11/03 14:57:32 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h" #include "libft.h"
void *ft_memcpy(void *dst, const void *src, size_t n) void *ft_memcpy(void *dst, const void *src, size_t n)

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memdel.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:57:33 by jhalford #+# #+# */
/* Updated: 2016/11/03 14:57:33 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h" #include "libft.h"
void ft_memdel(void **ap) void ft_memdel(void **ap)

View file

@ -1,14 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memmove.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:57:34 by jhalford #+# #+# */
/* Updated: 2016/11/03 15:53:48 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h" #include "libft.h"
void *ft_memmove(void *dst, const void *src, size_t len) void *ft_memmove(void *dst, const void *src, size_t len)
{ {
char *srcc;
char *dstc;
size_t i; size_t i;
i = 0; i = -1;
while (i < len && (dst + i < src || dst + i > src + len)) srcc = (char *)src;
{ dstc = (char *)dst;
((char *)dst)[i] = ((char *)src)[i]; if (srcc < dstc)
i++; while ((int)(--len) >= 0)
} *(dstc + len) = *(srcc + len);
else
while (++i < len)
*(dstc + i) = *(srcc + i);
return (dst); return (dst);
} }

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memset.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:57:36 by jhalford #+# #+# */
/* Updated: 2016/11/03 14:57:36 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h" #include "libft.h"
void *ft_memset(void *b, int c, size_t len) void *ft_memset(void *b, int c, size_t len)

View file

@ -1,7 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putchar.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:57:37 by jhalford #+# #+# */
/* Updated: 2016/11/03 14:57:38 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h" #include "libft.h"
int ft_putchar(int c) void ft_putchar(char c)
{ {
write(1, &c, 1); write(1, &c, 1);
return (0);
} }

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putchar_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:57:39 by jhalford #+# #+# */
/* Updated: 2016/11/03 14:57:39 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h" #include "libft.h"
void ft_putchar_fd(char c, int fd) void ft_putchar_fd(char c, int fd)

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putendl.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:57:40 by jhalford #+# #+# */
/* Updated: 2016/11/03 14:57:41 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h" #include "libft.h"
void ft_putendl(char const *s) void ft_putendl(char const *s)

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putendl_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:57:42 by jhalford #+# #+# */
/* Updated: 2016/11/03 14:57:42 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h" #include "libft.h"
void ft_putendl_fd(char const *s, int fd) void ft_putendl_fd(char const *s, int fd)

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putstr_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:57:48 by jhalford #+# #+# */
/* Updated: 2016/11/03 14:57:49 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h" #include "libft.h"
void ft_putstr_fd(char const *s, int fd) void ft_putstr_fd(char const *s, int fd)

View file

@ -6,10 +6,12 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/03 16:17:21 by jhalford #+# #+# */ /* Created: 2016/08/03 16:17:21 by jhalford #+# #+# */
/* Updated: 2016/08/07 18:10:10 by jhalford ### ########.fr */ /* Updated: 2016/11/03 15:13:04 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "libft.h"
static int ft_iswhitespace(char c) static int ft_iswhitespace(char c)
{ {
if (c == ' ' || c == '\t' || c == '\n') if (c == ' ' || c == '\t' || c == '\n')

View file

@ -19,7 +19,7 @@ char *ft_strcat(char *s1, const char *s2)
size = ft_strlen(s1); size = ft_strlen(s1);
j = 0; j = 0;
while (s2 && s2[j] != '\0') while (s2[j] != '\0')
{ {
s1[size + j] = s2[j]; s1[size + j] = s2[j];
j++; j++;

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:57:53 by jhalford #+# #+# */
/* Updated: 2016/11/03 15:07:30 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h" #include "libft.h"
char *ft_strchr(const char *s, int c) char *ft_strchr(const char *s, int c)

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strclr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:57:54 by jhalford #+# #+# */
/* Updated: 2016/11/03 14:57:55 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h" #include "libft.h"
void ft_strclr(char *s) void ft_strclr(char *s)

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/07 10:49:02 by jhalford #+# #+# */ /* Created: 2016/08/07 10:49:02 by jhalford #+# #+# */
/* Updated: 2016/08/25 17:06:34 by jhalford ### ########.fr */ /* Updated: 2016/11/03 16:08:51 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,18 +14,10 @@
int ft_strcmp(const char *s1, const char *s2) int ft_strcmp(const char *s1, const char *s2)
{ {
int cmp;
int i; int i;
i = 0; i = 0;
while (1) while (*(s1 + i) && *(s1 + i) == *(s2 + i))
{
cmp = (s1[i] - s2[i]);
if (s1[i] == '\0' && s2[i] == '\0')
return (cmp);
if (s1[i] == s2[i])
i++; i++;
else return (*((unsigned char*)s1 + i) - *((unsigned char*)s2 + i));
return (cmp);
}
} }

View file

@ -1,8 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdel.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:58:00 by jhalford #+# #+# */
/* Updated: 2016/11/03 14:58:00 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h" #include "libft.h"
void ft_strdel(char **as) void ft_strdel(char **as)
{ {
if (as)
free(*as); free(*as);
*as = NULL; *as = NULL;
} }

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:58:01 by jhalford #+# #+# */
/* Updated: 2016/11/03 14:58:02 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h" #include "libft.h"
char *ft_strdup(const char *s1) char *ft_strdup(const char *s1)

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strequ.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:58:04 by jhalford #+# #+# */
/* Updated: 2016/11/03 15:02:10 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h" #include "libft.h"
int ft_strequ(char const *s1, char const *s2) int ft_strequ(char const *s1, char const *s2)

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_striter.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:58:13 by jhalford #+# #+# */
/* Updated: 2016/11/03 14:58:13 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h" #include "libft.h"
void ft_striter(char *s, void (*f)(char *)) void ft_striter(char *s, void (*f)(char *))

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_striteri.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:58:15 by jhalford #+# #+# */
/* Updated: 2016/11/03 14:58:15 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h" #include "libft.h"
void ft_striteri(char *s, void (*f)(unsigned int, char *)) void ft_striteri(char *s, void (*f)(unsigned int, char *))

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:58:18 by jhalford #+# #+# */
/* Updated: 2016/11/03 14:58:18 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h" #include "libft.h"
char *ft_strjoin(char const *s1, char const *s2) char *ft_strjoin(char const *s1, char const *s2)

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlen.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:58:22 by jhalford #+# #+# */
/* Updated: 2016/11/03 14:58:23 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h" #include "libft.h"
size_t ft_strlen(const char *s) size_t ft_strlen(const char *s)

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:58:24 by jhalford #+# #+# */
/* Updated: 2016/11/03 14:58:25 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h" #include "libft.h"
char *ft_strmap(char const *s, char (*f)(char)) char *ft_strmap(char const *s, char (*f)(char))

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmapi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:58:28 by jhalford #+# #+# */
/* Updated: 2016/11/03 14:58:29 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h" #include "libft.h"
char *ft_strmapi(char const *s, char (*f)(unsigned int, char)) char *ft_strmapi(char const *s, char (*f)(unsigned int, char))

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/07 10:57:07 by jhalford #+# #+# */ /* Created: 2016/08/07 10:57:07 by jhalford #+# #+# */
/* Updated: 2016/08/07 10:57:11 by jhalford ### ########.fr */ /* Updated: 2016/11/03 15:02:27 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,7 +14,7 @@
char *ft_strncat(char *s1, const char *s2, size_t n) char *ft_strncat(char *s1, const char *s2, size_t n)
{ {
size_t size;; size_t size;
size_t j; size_t j;
size = ft_strlen(s1); size = ft_strlen(s1);

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/07 10:49:12 by jhalford #+# #+# */ /* Created: 2016/08/07 10:49:12 by jhalford #+# #+# */
/* Updated: 2016/08/15 22:25:07 by jhalford ### ########.fr */ /* Updated: 2016/11/03 16:11:00 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,20 +14,13 @@
int ft_strncmp(const char *s1, const char *s2, size_t n) int ft_strncmp(const char *s1, const char *s2, size_t n)
{ {
int cmp; int i;
size_t i;
i = 0; i = 0;
while (1) while (*(s1 + i) && *(s1 + i) == *(s2 + i) && i < (int)n)
{
cmp = (s1[i] - s2[i]);
if (i >= n - 1)
return (cmp);
if (s1[i] == '\0' && s2[i] == '\0')
return (cmp);
if (s1[i] == s2[i])
i++; i++;
if (i < (int)n)
return (*((unsigned char*)s1 + i) - *((unsigned char*)s2 + i));
else else
return (cmp); return (0);
}
} }

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnequ.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:58:32 by jhalford #+# #+# */
/* Updated: 2016/11/03 15:02:36 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h" #include "libft.h"
int ft_strnequ(char const *s1, char const *s2, size_t n) int ft_strnequ(char const *s1, char const *s2, size_t n)

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnew.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:58:34 by jhalford #+# #+# */
/* Updated: 2016/11/03 14:58:35 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h" #include "libft.h"
char *ft_strnew(size_t size) char *ft_strnew(size_t size)

View file

@ -1,23 +1,34 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:58:36 by jhalford #+# #+# */
/* Updated: 2016/11/03 16:34:42 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h" #include "libft.h"
char *ft_strnstr(const char *big, const char *little, size_t len) char *ft_strnstr(const char *big, const char *little, size_t len)
{ {
size_t i; size_t i;
size_t j; int j;
char *a;
a = (char *)big; i = -1;
i = 0; if (!*little)
while (a[i] != '\0' && i < len) return ((char *)big);
while (big[++i] && i < len)
{ {
j = 0; j = 0;
while (a[i + j] == little[j]) while (big[i + j] == little[j] && i + j < len)
{ {
j++; j++;
if (little[j] == '\0') if (!little[j])
return (a + i); return ((char *)big + i);
} }
i++;
} }
return (NULL); return (NULL);
} }

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strrchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:58:38 by jhalford #+# #+# */
/* Updated: 2016/11/03 15:08:33 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h" #include "libft.h"
char *ft_strrchr(const char *s, int c) char *ft_strrchr(const char *s, int c)

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strsplit.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:58:40 by jhalford #+# #+# */
/* Updated: 2016/11/03 15:00:19 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h" #include "libft.h"
static char **alloc_table(char **table, const char *str, char c) static char **alloc_table(char **table, const char *str, char c)
@ -85,8 +97,6 @@ char **ft_strsplit(char const *s, char c)
{ {
char **table; char **table;
if (!s)
return (NULL);
table = 0; table = 0;
table = alloc_table(table, s, c); table = alloc_table(table, s, c);
table = alloc_words(table, s, c); table = alloc_words(table, s, c);

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/07 10:48:35 by jhalford #+# #+# */ /* Created: 2016/08/07 10:48:35 by jhalford #+# #+# */
/* Updated: 2016/08/09 13:53:17 by jhalford ### ########.fr */ /* Updated: 2016/11/03 16:28:05 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,22 +14,24 @@
char *ft_strstr(const char *big, const char *little) char *ft_strstr(const char *big, const char *little)
{ {
size_t i; int i;
size_t j; int j;
char *a; char *a;
a = (char *)big; a = (char *)big;
i = 0; i = 0;
while (a[i] != '\0') if (!*little)
return (a);
while (a[i])
{ {
j = 0; j = 0;
while (a[i + j] == little[j]) while (a[i + j] == little[j])
{ {
j++; j++;
if (little[j] == '\0') if (!little[j])
return (a + i); return (a + i);
} }
i++; i++;
} }
return (0); return (NULL);
} }

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strsub.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:58:43 by jhalford #+# #+# */
/* Updated: 2016/11/03 14:58:43 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h" #include "libft.h"
char *ft_strsub(char const *s, unsigned int start, size_t len) char *ft_strsub(char const *s, unsigned int start, size_t len)

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:58:45 by jhalford #+# #+# */
/* Updated: 2016/11/03 14:58:45 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h" #include "libft.h"
char *ft_strtrim(char const *s) char *ft_strtrim(char const *s)