ft_strncmp

This commit is contained in:
Tanguy MAZE 2018-04-05 13:46:11 +02:00
parent 2446ae93b8
commit 9e7312327a
3 changed files with 32 additions and 3 deletions

View File

@ -6,7 +6,7 @@
# By: tmaze <marvin@42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2018/04/04 10:51:59 by tmaze #+# #+# #
# Updated: 2018/04/05 12:34:54 by tmaze ### ########.fr #
# Updated: 2018/04/05 13:16:24 by tmaze ### ########.fr #
# #
#******************************************************************************#
@ -28,6 +28,7 @@ SRCS = \
ft_strstr.c \
ft_strnstr.c \
ft_strcmp.c \
ft_strncmp.c \
ft_isalpha.c \
ft_isdigit.c \
ft_isalnum.c \

28
ft_strncmp.c Normal file
View File

@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tmaze <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/04/05 13:04:21 by tmaze #+# #+# */
/* Updated: 2018/04/05 13:15:51 by tmaze ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_strncmp(const char *s1, const char *s2, size_t n)
{
int i;
int diff;
i = 1;
diff = s1[0] - s2[0];
while ((unsigned int)i < n && diff == 0 && s1[i - 1] && s2[i - 1])
{
diff = s1[i] - s2[i];
i++;
}
return (diff);
}

View File

@ -6,7 +6,7 @@
/* By: tmaze <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/04/04 10:40:01 by tmaze #+# #+# */
/* Updated: 2018/04/05 11:39:51 by tmaze ### ########.fr */
/* Updated: 2018/04/05 13:11:35 by tmaze ### ########.fr */
/* */
/* ************************************************************************** */
@ -39,7 +39,7 @@ char *ft_strrchr(const char *s, int c);
char *ft_strstr(const char *haystack, const char *needle);
char *ft_strnstr(const char *haystack, const char *needle, size_t len);
int ft_strcmp(const char *s1, const char *s2);
int ft_strncmp(const char *s1, const char *s2);
int ft_strncmp(const char *s1, const char *s2, size_t n);
int ft_atoi(const char *nptr);
int ft_isalpha(int c);
int ft_isdigit(int c);