summaryrefslogtreecommitdiff
path: root/libft/ft_strncmp.c
diff options
context:
space:
mode:
Diffstat (limited to 'libft/ft_strncmp.c')
-rw-r--r--libft/ft_strncmp.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/libft/ft_strncmp.c b/libft/ft_strncmp.c
new file mode 100644
index 0000000..7861842
--- /dev/null
+++ b/libft/ft_strncmp.c
@@ -0,0 +1,29 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_strncmp.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: kdx <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2022/07/18 18:00:30 by kdx #+# #+# */
+/* Updated: 2022/10/14 02:34:13 by kdx ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft.h"
+
+int ft_strncmp(const char *s1, const char *s2, size_t n)
+{
+ if (n == 0)
+ return (0);
+ n -= 1;
+ while (n > 0 && (*s1 != '\0' || *s2 != '\0'))
+ {
+ if (*s1 != *s2)
+ return ((unsigned char)*s1 - (unsigned char)*s2);
+ s1 += 1;
+ s2 += 1;
+ n -= 1;
+ }
+ return ((unsigned char)*s1 - (unsigned char)*s2);
+}