ft_strncmp.c
1 /* ************************************************************************** */ 2 /* */ 3 /* ::: :::::::: */ 4 /* ft_strncmp.c :+: :+: :+: */ 5 /* +:+ +:+ +:+ */ 6 /* By: ll-hotel <ll-hotel@student.42lyon.fr> +#+ +:+ +#+ */ 7 /* +#+#+#+#+#+ +#+ */ 8 /* Created: 2023/11/07 15:01:42 by ll-hotel #+# #+# */ 9 /* Updated: 2024/10/18 14:27:26 by ll-hotel ### ########.fr */ 10 /* */ 11 /* ************************************************************************** */ 12 13 #include <stddef.h> 14 15 int ft_strncmp(const char *s1, const char *s2, size_t n) 16 { 17 size_t i; 18 19 i = 0; 20 while (i + 1 < n && s1[i] && s1[i] == s2[i]) 21 i++; 22 return ((n > 0) * ((unsigned char)s1[i] - (unsigned char)s2[i])); 23 } 24 25 int ft_strcmp(const char *s1, const char *s2) 26 { 27 size_t i; 28 29 if (s1 == NULL && s2 == NULL) 30 return (0); 31 i = 0; 32 while (s1[i] && s1[i] == s2[i]) 33 i++; 34 return ((unsigned char)s1[i] - (unsigned char)s2[i]); 35 }