aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2020-02-10 04:24:29 +0100
committerCharles <sircharlesaze@gmail.com>2020-02-10 04:24:29 +0100
commitfc457992114e71989e5cdeab452bc054a400a397 (patch)
tree4078af0485fe91f3bbf56984c2a3f171ff2f51de /src
parent4800d3ca472058f0161970aa55c6debb453e5d00 (diff)
downloadlibft-fc457992114e71989e5cdeab452bc054a400a397.tar.gz
libft-fc457992114e71989e5cdeab452bc054a400a397.tar.bz2
libft-fc457992114e71989e5cdeab452bc054a400a397.zip
Fixing ft_strcmp, Added ft_strcasecmp, ft_strncasecmp
Diffstat (limited to 'src')
-rw-r--r--src/algo/ft_heapsort.c6
-rw-r--r--src/str/ft_strcasecmp.c24
-rw-r--r--src/str/ft_strcmp.c9
-rw-r--r--src/str/ft_strncasecmp.c26
-rw-r--r--src/str/ft_strncmp.c5
-rw-r--r--src/str/ft_strtolower.c26
-rw-r--r--src/str/ft_strtoupper.c26
7 files changed, 117 insertions, 5 deletions
diff --git a/src/algo/ft_heapsort.c b/src/algo/ft_heapsort.c
index afd395d..d309624 100644
--- a/src/algo/ft_heapsort.c
+++ b/src/algo/ft_heapsort.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/10 02:59:22 by cacharle #+# #+# */
-/* Updated: 2020/02/10 03:57:50 by cacharle ### ########.fr */
+/* Updated: 2020/02/10 04:22:19 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -35,6 +35,10 @@
int ft_heapsort(void *base, size_t nel, size_t width,
int (*compar)(const void *, const void *))
{
+ (void)base;
+ (void)nel;
+ (void)width;
+ (void)compar;
/* size_t i; */
/* */
/* if (nel < 2) */
diff --git a/src/str/ft_strcasecmp.c b/src/str/ft_strcasecmp.c
new file mode 100644
index 0000000..45ba592
--- /dev/null
+++ b/src/str/ft_strcasecmp.c
@@ -0,0 +1,24 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_strcasecmp.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/10 04:08:38 by cacharle #+# #+# */
+/* Updated: 2020/02/10 04:22:56 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft_str.h"
+#include "libft_types.h"
+
+int strcasecmp(const char *s1, const char *s2)
+{
+ while (*s1 && *s2 && ft_tolower(*s1) == ft_tolower(*s2))
+ {
+ s1++;
+ s2++;
+ }
+ return ((t_ftuchar)ft_tolower(*s1) - (t_ftuchar)ft_tolower(*s2));
+}
diff --git a/src/str/ft_strcmp.c b/src/str/ft_strcmp.c
index 1978286..aced711 100644
--- a/src/str/ft_strcmp.c
+++ b/src/str/ft_strcmp.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/07 10:16:07 by cacharle #+# #+# */
-/* Updated: 2019/11/21 01:58:27 by cacharle ### ########.fr */
+/* Updated: 2020/02/10 04:18:11 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -14,5 +14,10 @@
int ft_strcmp(const char *s1, const char *s2)
{
- return (ft_memcmp(s1, s2, ft_strlen(s1) + 1));
+ while (*s1 && *s2 && *s1 == *s2)
+ {
+ s1++;
+ s2++;
+ }
+ return (*s1 - *s2);
}
diff --git a/src/str/ft_strncasecmp.c b/src/str/ft_strncasecmp.c
new file mode 100644
index 0000000..1b6308d
--- /dev/null
+++ b/src/str/ft_strncasecmp.c
@@ -0,0 +1,26 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_strncasecmp.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/10 04:18:36 by cacharle #+# #+# */
+/* Updated: 2020/02/10 04:21:10 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft.h"
+#include "libft_types.h"
+
+int strncasecmp(const char *s1, const char *s2, size_t n)
+{
+ size_t i;
+
+ if (n == 0)
+ return (0);
+ i = 0;
+ while (i + 1 < n && s1[i] && ft_tolower(s1[i]) == ft_tolower(s2[i]))
+ i++;
+ return ((t_ftuchar)ft_tolower(s1[i]) - (t_ftuchar)ft_tolower(s2[i]));
+}
diff --git a/src/str/ft_strncmp.c b/src/str/ft_strncmp.c
index cd303fc..caa052b 100644
--- a/src/str/ft_strncmp.c
+++ b/src/str/ft_strncmp.c
@@ -6,11 +6,12 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/07 10:27:34 by cacharle #+# #+# */
-/* Updated: 2019/11/21 01:56:32 by cacharle ### ########.fr */
+/* Updated: 2020/02/10 04:17:50 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
+#include "libft_types.h"
int ft_strncmp(const char *s1, const char *s2, size_t n)
{
@@ -21,5 +22,5 @@ int ft_strncmp(const char *s1, const char *s2, size_t n)
i = 0;
while (i + 1 < n && s1[i] == s2[i] && s1[i])
i++;
- return ((unsigned char)s1[i] - (unsigned char)s2[i]);
+ return ((t_ftuchar)s1[i] - (t_ftuchar)s2[i]);
}
diff --git a/src/str/ft_strtolower.c b/src/str/ft_strtolower.c
new file mode 100644
index 0000000..2eb34c2
--- /dev/null
+++ b/src/str/ft_strtolower.c
@@ -0,0 +1,26 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_strtolower.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/10 04:10:01 by cacharle #+# #+# */
+/* Updated: 2020/02/10 04:12:21 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft_str.h"
+#include "libft_ctype.h"
+
+char *ft_strtolower(char *s)
+{
+ int i;
+
+ if (s == NULL)
+ return (NULL);
+ i = -1;
+ while (s[i])
+ s[i] = ft_tolower(s[i]);
+ return (s);
+}
diff --git a/src/str/ft_strtoupper.c b/src/str/ft_strtoupper.c
new file mode 100644
index 0000000..d4c49d5
--- /dev/null
+++ b/src/str/ft_strtoupper.c
@@ -0,0 +1,26 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_strtoupper.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/10 04:12:04 by cacharle #+# #+# */
+/* Updated: 2020/02/10 04:12:17 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft_str.h"
+#include "libft_ctype.h"
+
+char *ft_strtolower(char *s)
+{
+ int i;
+
+ if (s == NULL)
+ return (NULL);
+ i = -1;
+ while (s[i])
+ s[i] = ft_tolower(s[i]);
+ return (s);
+}