aboutsummaryrefslogtreecommitdiff
path: root/ft_memcmp.c
diff options
context:
space:
mode:
Diffstat (limited to 'ft_memcmp.c')
-rw-r--r--ft_memcmp.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/ft_memcmp.c b/ft_memcmp.c
new file mode 100644
index 0000000..76cd47d
--- /dev/null
+++ b/ft_memcmp.c
@@ -0,0 +1,19 @@
+#include <string.h>
+
+int ft_memcmp(const void *s1, const void *s2, size_t n)
+{
+ size_t i;
+ unsigned char *uc_s1;
+ unsigned char *uc_s2;
+
+ uc_s1 = (unsigned char*)s1;
+ uc_s2 = (unsigned char*)s2;
+ i = 0;
+ if (n == 0)
+ return (0);
+ while (i < n && uc_s1[i] == uc_s2[i])
+ i++;
+ if (i == n)
+ i--;
+ return (uc_s1[i] - uc_s2[i]);
+}