aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--ft_lstnew_bonus.c2
-rw-r--r--ft_memmove.c2
-rw-r--r--ft_strlcat.c12
-rw-r--r--ft_strnstr.c13
-rw-r--r--libft.h3
6 files changed, 21 insertions, 12 deletions
diff --git a/.gitignore b/.gitignore
index 8cef4ae..56fd0f2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,4 @@ a.out
*.o
*.so
*.a
+main.c
diff --git a/ft_lstnew_bonus.c b/ft_lstnew_bonus.c
index 9f09a85..826499e 100644
--- a/ft_lstnew_bonus.c
+++ b/ft_lstnew_bonus.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/09 09:01:16 by cacharle #+# #+# */
-/* Updated: 2019/10/09 09:07:37 by cacharle ### ########.fr */
+/* Updated: 2019/10/10 14:51:30 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
diff --git a/ft_memmove.c b/ft_memmove.c
index 1c97fab..cc05875 100644
--- a/ft_memmove.c
+++ b/ft_memmove.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/07 10:03:21 by cacharle #+# #+# */
-/* Updated: 2019/10/09 09:06:05 by cacharle ### ########.fr */
+/* Updated: 2019/10/10 14:56:41 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
diff --git a/ft_strlcat.c b/ft_strlcat.c
index ad21642..241e158 100644
--- a/ft_strlcat.c
+++ b/ft_strlcat.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/07 10:31:37 by cacharle #+# #+# */
-/* Updated: 2019/10/09 12:43:28 by cacharle ### ########.fr */
+/* Updated: 2019/10/12 13:09:02 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -16,6 +16,7 @@
size_t ft_strlcat(char *dst, const char *src, size_t size)
{
size_t i;
+ size_t j;
size_t dst_len;
size_t src_len;
@@ -23,12 +24,15 @@ size_t ft_strlcat(char *dst, const char *src, size_t size)
src_len = ft_strlen(src);
if (size == 0)
return (src_len);
- i = dst_len;
- while (i < size - 1)
+ i = 0;
+ j = dst_len;
+ while (src[i] && j < size - 1)
{
- dst[i] = src[i - dst_len];
+ dst[j] = src[i];
i++;
+ j++;
}
+ dst[j] = '\0';
if (dst[size - 1] != '\0')
return (src_len + size);
return (dst_len + src_len);
diff --git a/ft_strnstr.c b/ft_strnstr.c
index d65a6f6..ebe2fcf 100644
--- a/ft_strnstr.c
+++ b/ft_strnstr.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/07 10:25:13 by cacharle #+# #+# */
-/* Updated: 2019/10/07 12:40:59 by cacharle ### ########.fr */
+/* Updated: 2019/10/12 13:51:56 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -21,10 +21,14 @@ char *ft_strnstr(const char *haystack, const char *needle, size_t len)
size_t needle_len;
needle_len = ft_strlen(needle);
- if (needle_len == 0 || len == 0)
+ if (needle_len == 0 && len == 0)
return ((char*)haystack);
- i = 0;
- while (i < len && haystack[i])
+ if (len == 0)
+ return (NULL);
+ if (needle_len == 0)
+ return ((char*)haystack);
+ i = -1;
+ while (++i < len && haystack[i])
{
j = 0;
while (i + j < len && needle[j] && haystack[i + j])
@@ -35,7 +39,6 @@ char *ft_strnstr(const char *haystack, const char *needle, size_t len)
}
if (j == needle_len)
return ((char*)haystack + i);
- i++;
}
return (NULL);
}
diff --git a/libft.h b/libft.h
index a7da118..31fcfe0 100644
--- a/libft.h
+++ b/libft.h
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/07 09:45:02 by cacharle #+# #+# */
-/* Updated: 2019/10/09 08:58:46 by cacharle ### ########.fr */
+/* Updated: 2019/10/11 14:58:42 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -48,6 +48,7 @@ int ft_isalnum(int c);
int ft_isascii(int c);
int ft_isprint(int c);
int ft_toupper(int c);
+int ft_tolower(int c);
void *ft_calloc(size_t count, size_t size);
void *ft_memalloc(size_t size);
void ft_memdel(void **ap);