Browse Source

until strncat

master
Elouan MARTINET 4 years ago
parent
commit
ab42cf28f5
  1. 26
      ft_memchr.c
  2. 29
      ft_memcmp.c
  3. 2
      ft_strncpy.c

26
ft_memchr.c

@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: emartine <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/11/07 19:12:29 by emartine #+# #+# */
/* Updated: 2017/11/07 19:12:30 by emartine ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memchr(const void *s, int c, size_t n)
{
unsigned char *cs;
unsigned char cc;
cs = (unsigned char *)s;
cc = (unsigned char)c;
while (n--)
if (*(cs++) == c)
return (cs - 1);
return (NULL);
}

29
ft_memcmp.c

@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: emartine <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/11/07 19:17:31 by emartine #+# #+# */
/* Updated: 2017/11/07 19:17:32 by emartine ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_memcmp(const void *s1, const void *s2, size_t n)
{
unsigned char *c1;
unsigned char *c2;
size_t i;
if (s1 == s2 || n == 0)
return (0);
c1 = (unsigned char *)s1;
c2 = (unsigned char *)s2;
i = 0;
while (n-- && c1[i] == c2[i])
i++;
return (c1[i] - c2[i]);
}

2
ft_strncpy.c

@ -14,7 +14,7 @@
char *ft_strncpy(char *dest, const char *src, size_t n)
{
unsigned int i;
size_t i;
i = 0;
while (i < n && src[i] != '\0')

Loading…
Cancel
Save