Update ft_strcmp & ft_strncmp
This commit is contained in:
@@ -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]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user