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