libft
ft_strncmp.c
Go to the documentation of this file.
1 /* ************************************************************************** */
3 /* */
4 /* ::: :::::::: */
5 /* ft_strncmp.c :+: :+: :+: */
6 /* +:+ +:+ +:+ */
7 /* By: unite <marvin@42.fr> +#+ +:+ +#+ */
8 /* +#+#+#+#+#+ +#+ */
9 /* Created: 2019/09/19 19:33:19 by unite #+# #+# */
10 /* Updated: 2020/07/16 02:41:56 by unite ### ########.fr */
11 /* */
12 /* ************************************************************************** */
13 
14 #include "libft.h"
15 
20 int ft_strncmp(const char *s1, const char *s2, size_t n)
21 {
22  unsigned char *s1u;
23  unsigned char *s2u;
24 
25  s1u = (unsigned char *)s1;
26  s2u = (unsigned char *)s2;
27  while ((*s1u || *s2u) && n-- > 0)
28  {
29  if (*s1u - *s2u)
30  return (*s1u - *s2u);
31  s1u++;
32  s2u++;
33  }
34  return (0);
35 }
ft_strncmp
int ft_strncmp(const char *s1, const char *s2, size_t n)
Replicates behaviour of strncmp from libc.
Definition: ft_strncmp.c:20
libft.h