ft_memcmp: initial implementation
also fix a small clarity issue in ft_strncmp
This commit is contained in:
parent
b81ad331b5
commit
1c3df31518
4 changed files with 54 additions and 4 deletions
48
ft_memcmp.c
Normal file
48
ft_memcmp.c
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memcmp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: kcolin <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/16 15:26:08 by kcolin #+# #+# */
|
||||
/* Updated: 2024/10/16 15:31:27 by kcolin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_memcmp(const void *s1, const void *s2, size_t n)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
while (1)
|
||||
{
|
||||
if (i >= n)
|
||||
return (0);
|
||||
if (((unsigned char *)s1)[i] != ((unsigned char *)s2)[i])
|
||||
break ;
|
||||
i++;
|
||||
}
|
||||
return (((unsigned char *)s1)[i] - ((unsigned char *)s2)[i]);
|
||||
}
|
||||
|
||||
/*
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
size_t cmp_len;
|
||||
|
||||
cmp_len = 0;
|
||||
if (argc > 2)
|
||||
{
|
||||
printf("mine: %d\tlib: %d\n",
|
||||
ft_memcmp(argv[1], argv[2], cmp_len),
|
||||
memcmp(argv[1], argv[2], cmp_len));
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
*/
|
||||
Loading…
Add table
Add a link
Reference in a new issue