aboutsummaryrefslogtreecommitdiff
path: root/ft_strncmp.c
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2019-11-21 02:06:06 +0100
committerCharles <sircharlesaze@gmail.com>2019-11-21 02:06:06 +0100
commitafc8c70a66773563f6e7429b500abcbab631722b (patch)
tree731b50b430b493280ce97a557f86f45cb2f37780 /ft_strncmp.c
parentf96be9ba455b0a71562e732664717b507b4bd548 (diff)
downloadlibft-afc8c70a66773563f6e7429b500abcbab631722b.tar.gz
libft-afc8c70a66773563f6e7429b500abcbab631722b.tar.bz2
libft-afc8c70a66773563f6e7429b500abcbab631722b.zip
ft_memset and ft_strlen optimization
Diffstat (limited to 'ft_strncmp.c')
-rw-r--r--ft_strncmp.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/ft_strncmp.c b/ft_strncmp.c
index 46f79c2..cd303fc 100644
--- a/ft_strncmp.c
+++ b/ft_strncmp.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/07 10:27:34 by cacharle #+# #+# */
-/* Updated: 2019/11/20 03:33:59 by cacharle ### ########.fr */
+/* Updated: 2019/11/21 01:56:32 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -16,10 +16,10 @@ int ft_strncmp(const char *s1, const char *s2, size_t n)
{
size_t i;
+ if (n == 0)
+ return (0);
i = 0;
- while (i < n && s1[i] == s2[i] && s1[i] && s2[i])
+ while (i + 1 < n && s1[i] == s2[i] && s1[i])
i++;
- if (i == n)
- i--;
- return (((unsigned char*)s1)[i] - ((unsigned char*)s2)[i]);
+ return ((unsigned char)s1[i] - (unsigned char)s2[i]);
}