Update ft_strcmp & ft_strncmp

This commit is contained in:
lclerel- lclerel-
2026-03-25 16:40:08 +01:00
parent e3190ac977
commit 19739f2619
4 changed files with 11 additions and 9 deletions
+3 -3
View File
@@ -6,10 +6,10 @@
/* By: lclerel- <lclerel-@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/03/24 13:44:05 by lclerel- #+# #+# */
/* Updated: 2026/03/24 15:55:40 by lclerel- ### ########.fr */
/* Updated: 2026/03/25 16:39:14 by lclerel- ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
int ft_strncmp(char *s1, char *s2, unsigned int n)
{
@@ -18,7 +18,7 @@ int ft_strncmp(char *s1, char *s2, unsigned int n)
i = 0;
if (n == 0)
return (0);
while (s1[i] != '\0' && s1[i] == s2[i] && i < n - 1)
while ((s1[i] || s2[i]) && s1[i] == s2[i] && i < n - 1)
i++;
return ((unsigned char)s1[i] - (unsigned char)s2[i]);
}