/ libft / src / ft_basics / ft_memcmp.c
ft_memcmp.c
 1  /* ************************************************************************** */
 2  /*                                                                            */
 3  /*                                                        :::      ::::::::   */
 4  /*   ft_memcmp.c                                        :+:      :+:    :+:   */
 5  /*                                                    +:+ +:+         +:+     */
 6  /*   By: ll-hotel <ll-hotel@student.42lyon.fr>      +#+  +:+       +#+        */
 7  /*                                                +#+#+#+#+#+   +#+           */
 8  /*   Created: 2023/11/07 15:52:30 by ll-hotel          #+#    #+#             */
 9  /*   Updated: 2023/11/09 13:40:04 by ll-hotel         ###   ########.fr       */
10  /*                                                                            */
11  /* ************************************************************************** */
12  
13  #include <stddef.h>
14  
15  int	ft_memcmp(const void *s1, const void *s2, unsigned long long n)
16  {
17  	unsigned long long	i;
18  	const unsigned char	*p1 = (unsigned char *)s1;
19  	const unsigned char	*p2 = (unsigned char *)s2;
20  
21  	i = 0;
22  	while (i < n && p1[i] == p2[i])
23  		i++;
24  	if (i < n)
25  		return (p1[i] - p2[i]);
26  	return (0);
27  }