base struct
This commit is contained in:
33
lib/libft/srcs/str/ft_strncmp.c
Normal file
33
lib/libft/srcs/str/ft_strncmp.c
Normal file
@@ -0,0 +1,33 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strncmp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/14 10:58:07 by nalebrun #+# #+# */
|
||||
/* Updated: 2024/11/25 16:16:32 by nalebrun ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../../libft.h"
|
||||
|
||||
int ft_strncmp(const char *s1, const char *s2, size_t n)
|
||||
{
|
||||
size_t i;
|
||||
unsigned char *ss1;
|
||||
unsigned char *ss2;
|
||||
|
||||
if (!s1 || !s2)
|
||||
return (0);
|
||||
i = 0;
|
||||
ss1 = (unsigned char *)s1;
|
||||
ss2 = (unsigned char *)s2;
|
||||
if (n == 0)
|
||||
return (0);
|
||||
while (i < n && ss1[i] && ss2[i] && ss1[i] == ss2[i])
|
||||
i++;
|
||||
if (i == n)
|
||||
return (0);
|
||||
return (ss1[i] - ss2[i]);
|
||||
}
|
||||
Reference in New Issue
Block a user