summaryrefslogtreecommitdiff
path: root/ft_memcmp.c
blob: 0bd52df8af2f5bc779d9fbb25c309c917da2350b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   ft_memcmp.c                                        :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: dkaiser <dkaiser@student.42heilbronn.de    +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2024/03/06 15:54:13 by dkaiser           #+#    #+#             */
/*   Updated: 2024/03/10 13:13:54 by dkaiser          ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include "libft.h"

int	ft_memcmp(const void *s1, const void *s2, size_t n)
{
	size_t	i;
	int		result;

	i = 0;
	result = 0;
	while (!result && i < n)
	{
		result = *((unsigned char *)s1 + i) - *((unsigned char *)s2 + i);
		i++;
	}
	return (result);
}

/* #include <stdio.h> */

/* int	main(void) */
/* { */
/* 	char	str1[] = "Hello"; */
/* 	char	str2[] = "Hellu"; */

/* 	printf("memcmp: %d\n", memcmp(str1, str2, 5)); */
/* 	printf("ft_memcmp: %d\n", ft_memcmp(str1, str2, 5)); */
/* } */