Libft
42 Libft library documentation
Loading...
Searching...
No Matches
ft_memcmp.c File Reference
#include <stdlib.h>
+ Include dependency graph for ft_memcmp.c:

Go to the source code of this file.

Functions

int ft_memcmp (const void *s1, const void *s2, size_t n)
 Compares two memory areas byte by byte.
 

Function Documentation

◆ ft_memcmp()

int ft_memcmp ( const void *  s1,
const void *  s2,
size_t  n 
)

Compares two memory areas byte by byte.

Parameters
s1First memory area.
s2Second memory area.
nNumber of bytes to compare.
Returns
Negative, zero, or positive difference at first mismatch.

Definition at line 23 of file ft_memcmp.c.

24{
25 const unsigned char *p1;
26 const unsigned char *p2;
27
28 p1 = (const unsigned char *)s1;
29 p2 = (const unsigned char *)s2;
30 while (n--)
31 {
32 if (*p1 != *p2)
33 return (*p1 - *p2);
34 p1++;
35 p2++;
36 }
37 return (0);
38}