Browse Source

correct

master
Elouan MARTINET 4 years ago
parent
commit
428e812639
  1. 9
      Makefile
  2. 5
      ft_strclr.c
  3. 3
      ft_strdel.c
  4. 4
      ft_strequ.c
  5. 5
      ft_striter.c
  6. 5
      ft_striteri.c
  7. 2
      ft_strjoin.c
  8. 4
      ft_strlen.c
  9. 6
      ft_strmap.c
  10. 4
      ft_strmapi.c
  11. 2
      ft_strncmp.c
  12. 4
      ft_strnequ.c
  13. 2
      ft_strsplit.c
  14. 2
      ft_strsub.c
  15. 2
      ft_strtrim.c
  16. 10
      libft.h

9
Makefile

@ -11,12 +11,21 @@ SRC := \
ft_isprint.c \
ft_isspace.c \
ft_itoa.c \
ft_lstadd.c \
ft_lstdel.c \
ft_lstdelone.c \
ft_lstiter.c \
ft_lstlen.c \
ft_lstmap.c \
ft_lstncreate.c \
ft_lstnew.c \
ft_memalloc.c \
ft_memccpy.c \
ft_memchr.c \
ft_memcmp.c \
ft_memcpy.c \
ft_memdel.c \
ft_memdup.c \
ft_memmove.c \
ft_memset.c \
ft_putchar.c \

5
ft_strclr.c

@ -14,6 +14,7 @@
void ft_strclr(char *s)
{
while (*s)
*(s++) = '\0';
if (s)
while (*s)
*(s++) = '\0';
}

3
ft_strdel.c

@ -14,5 +14,6 @@
void ft_strdel(char **as)
{
ft_memdel((void **)as);
if (as && *as)
ft_memdel((void **)as);
}

4
ft_strequ.c

@ -14,5 +14,9 @@
int ft_strequ(char const *s1, char const *s2)
{
if (s1 == s2)
return (1);
if (!s1 || !s2)
return (0);
return (ft_strcmp(s1, s2) == 0);
}

5
ft_striter.c

@ -14,6 +14,7 @@
void ft_striter(char *s, void (*f)(char *))
{
while (*s)
f(s++);
if (s && f)
while (*s)
f(s++);
}

5
ft_striteri.c

@ -17,6 +17,7 @@ void ft_striteri(char *s, void (*f)(unsigned int, char *))
unsigned int i;
i = 0;
while (*s)
f(i++, s++);
if (s && f)
while (*s)
f(i++, s++);
}

2
ft_strjoin.c

@ -19,7 +19,7 @@ char *ft_strjoin(char const *s1, char const *s2)
char *c2;
size_t i;
if (!(r = (char *)malloc(ft_strlen(s1) + ft_strlen(s2) + 1)))
if (!s1 || !s2 || !(r = (char *)malloc(ft_strlen(s1) + ft_strlen(s2) + 1)))
return (NULL);
c1 = (char *)s1;
c2 = (char *)s2;

4
ft_strlen.c

@ -12,9 +12,9 @@
#include "libft.h"
int ft_strlen(const char *str)
size_t ft_strlen(const char *str)
{
int r;
size_t r;
r = 0;
while (str[r])

6
ft_strmap.c

@ -15,9 +15,11 @@
char *ft_strmap(char const *s, char (*f)(char))
{
char *r;
int l;
int i;
size_t l;
size_t i;
if (!s || !f)
return (NULL);
l = ft_strlen(s);
if (!(r = (char *)malloc(l + 1)))
return (NULL);

4
ft_strmapi.c

@ -18,7 +18,9 @@ char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
unsigned int l;
unsigned int i;
l = (unsigned)ft_strlen(s);
if (!s || !f)
return (NULL);
l = ft_strlen(s);
if (!(r = (char *)malloc(l + 1)))
return (NULL);
i = 0;

2
ft_strncmp.c

@ -19,5 +19,7 @@ int ft_strncmp(const char *s1, const char *s2, size_t n)
i = 0;
while (i < n && s1[i] != '\0' && s2[i] != '\0' && s1[i] == s2[i])
i++;
if (i == n)
return (0);
return ((unsigned char)(s1[i]) - (unsigned char)(s2[i]));
}

4
ft_strnequ.c

@ -14,5 +14,9 @@
int ft_strnequ(char const *s1, char const *s2, size_t n)
{
if (s1 == s2)
return (1);
if (!s1 || !s2)
return (0);
return (ft_strncmp(s1, s2, n) == 0);
}

2
ft_strsplit.c

@ -74,6 +74,8 @@ char **ft_strsplit(char const *str, char c)
size_t words;
char **r;
if (!str)
return (NULL);
words = count_words(str, c);
if (!words)
{

2
ft_strsub.c

@ -17,7 +17,7 @@ char *ft_strsub(char const *s, unsigned intstart, size_t len)
char *r;
size_t i;
if (!(r = (char *)malloc(len + 1)))
if (!s || !(r = (char *)malloc(len + 1)))
return (NULL);
i = 0;
while (i < len && s[i])

2
ft_strtrim.c

@ -36,6 +36,8 @@ char *ft_strtrim(char const *s)
size_t start;
size_t end;
if (!s)
return (NULL);
end = ft_strlen(s);
start = 0;
if (end > 0)

10
libft.h

@ -24,7 +24,7 @@ void *ft_memccpy(void *dst, const void *src, int c, size_t n);
void *ft_memmove(void *dst, const void *src, size_t len);
void *ft_memchr(const void *s, int c, size_t n);
int ft_memcmp(const void *s1, const void *s2, size_t n);
int ft_strlen(const char *str);
size_t ft_strlen(const char *str);
char *ft_strdup(const char *s1);
char *ft_strcpy(char *dst, const char *src);
char *ft_strncpy(char *dst, const char *src, size_t len);
@ -70,8 +70,6 @@ void ft_putchar_fd(char c, int fd);
void ft_putstr_fd(char const *s, int fd);
void ft_putendl_fd(char const *s, int fd);
void ft_putnbr_fd(int n, int fd);
int ft_isspace(int c);
size_t ft_strnlen(const char *str, size_t maxlen);
typedef struct s_list
{
@ -87,4 +85,10 @@ void ft_lstadd(t_list **alst, t_list *new);
void ft_lstiter(t_list *lst, void (*f)(t_list *elem));
t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem));
int ft_isspace(int c);
size_t ft_strnlen(const char *str, size_t maxlen);
void *ft_memdup(const void *src, size_t len);
size_t ft_lstlen(const t_list *lst);
t_list *ft_lstncreate(size_t n);
#endif

Loading…
Cancel
Save