minishell
ft_strncmp.c
Go to the documentation of this file.
1 /* ************************************************************************** */
2 /* */
3 /* ::: :::::::: */
4 /* ft_strncmp.c :+: :+: :+: */
5 /* +:+ +:+ +:+ */
6 /* By: kfujita <kfujita@student.42tokyo.jp> +#+ +:+ +#+ */
7 /* +#+#+#+#+#+ +#+ */
8 /* Created: 2022/04/10 16:50:25 by kfujita #+# #+# */
9 /* Updated: 2022/04/25 23:29:28 by kfujita ### ########.fr */
10 /* */
11 /* ************************************************************************** */
12 
13 #include <stddef.h>
14 #include "ft_string.h"
15 
16 int ft_strncmp(const char *s1, const char *s2, size_t n)
17 {
18  if (n == 0)
19  return (0);
20  while (--n > 0 && *s1 == *s2 && *s1 != '\0')
21  {
22  s1++;
23  s2++;
24  }
25  return (*((unsigned char *)s1) - *((unsigned char *)s2));
26 }
int ft_strncmp(const char *s1, const char *s2, size_t n)
Definition: ft_strncmp.c:16