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
+6 -5
View File
@@ -6,7 +6,7 @@
/* By: lclerel- <lclerel-@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/03/24 13:44:05 by lclerel- #+# #+# */
/* Updated: 2026/03/24 15:55:22 by lclerel- ### ########.fr */
/* Updated: 2026/03/25 16:39:44 by lclerel- ### ########.fr */
/* */
/* ************************************************************************** */
@@ -17,11 +17,11 @@ int ft_strcmp(char *s1, char *s2)
int i;
i = 0;
while (s1[i] != '\0' && s1[i] == s2[i])
while ((s1[i] || s2[i]) && s1[i] == s2[i])
i++;
return ((unsigned char)s1[i] - (unsigned char)s2[i]);
}
/*
void ft_putchar(char chara)
{
write(1, &chara, 1);
@@ -38,7 +38,7 @@ void ft_putstr(char *str)
i++;
}
}
/*
int main(void)
{
char *s1 = "Lumi";
@@ -80,4 +80,5 @@ int main(void)
write(1, "Test 3 : Not OK :(", 18);
ft_putchar('\n');
return (0);
}*/
}
*/
+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]);
}