libft: add ft_strcmp function

This commit is contained in:
Khaïs COLIN 2025-02-13 15:28:38 +01:00
parent 897f6c6a6b
commit aad17031a8
Signed by: logistic-bot
SSH key fingerprint: SHA256:RlpiqKeXpcPFZZ4y9Ou4xi2M8OhRJovIwDlbCaMsuAo
3 changed files with 26 additions and 2 deletions

View file

@ -6,7 +6,7 @@
/* By: jguelen <marvin@42.fr> +#+ +:+ +#+ */ /* By: jguelen <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/17 16:06:09 by jguelen #+# #+# */ /* Created: 2024/10/17 16:06:09 by jguelen #+# #+# */
/* Updated: 2025/01/07 18:10:15 by jguelen ### ########.fr */ /* Updated: 2025/02/13 15:27:21 by khais ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -131,6 +131,7 @@ int ft_toupper(int c);
int ft_tolower(int c); int ft_tolower(int c);
char *ft_strchr(const char *s, int c); char *ft_strchr(const char *s, int c);
char *ft_strrchr(const char *s, int c); char *ft_strrchr(const char *s, int c);
int ft_strcmp(const char *s1, const char *s2);
int ft_strncmp(const char *s1, const char *s2, size_t n); int ft_strncmp(const char *s1, const char *s2, size_t n);
void *ft_memchr(const void *s, int c, size_t n); void *ft_memchr(const void *s, int c, size_t n);
int ft_memcmp(const void *s1, const void *s2, size_t n); int ft_memcmp(const void *s1, const void *s2, size_t n);

View file

@ -8,7 +8,7 @@ SOURCES = ft_atoi.c ft_itoa.c ft_putendl_fd.c ft_strlcat.c ft_substr.c \
ft_bzero.c ft_putnbr_fd.c ft_strlcpy.c ft_tolower.c ft_calloc.c \ ft_bzero.c ft_putnbr_fd.c ft_strlcpy.c ft_tolower.c ft_calloc.c \
ft_memchr.c ft_putstr_fd.c ft_strlen.c ft_toupper.c ft_isalnum.c \ ft_memchr.c ft_putstr_fd.c ft_strlen.c ft_toupper.c ft_isalnum.c \
ft_memcmp.c ft_split.c ft_strmapi.c ft_isalpha.c ft_memcpy.c ft_strchr.c \ ft_memcmp.c ft_split.c ft_strmapi.c ft_isalpha.c ft_memcpy.c ft_strchr.c \
ft_strncmp.c ft_isascii.c ft_memmove.c ft_strdup.c ft_strnstr.c \ ft_strcmp.c ft_strncmp.c ft_isascii.c ft_memmove.c ft_strdup.c ft_strnstr.c \
ft_isdigit.c ft_memset.c ft_striteri.c ft_strrchr.c ft_isprint.c \ ft_isdigit.c ft_memset.c ft_striteri.c ft_strrchr.c ft_isprint.c \
ft_putchar_fd.c ft_strjoin.c ft_strtrim.c ft_min_max.c ft_strjoin_sepc.c ft_putchar_fd.c ft_strjoin.c ft_strtrim.c ft_min_max.c ft_strjoin_sepc.c
BONUSSOURCES = ft_lstnew_bonus.c ft_lstadd_back_bonus.c ft_lstsize_bonus.c \ BONUSSOURCES = ft_lstnew_bonus.c ft_lstadd_back_bonus.c ft_lstsize_bonus.c \

23
libft/libft/ft_strcmp.c Normal file
View file

@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jguelen <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/17 12:34:03 by jguelen #+# #+# */
/* Updated: 2025/02/13 15:27:03 by khais ### ########.fr */
/* */
/* ************************************************************************** */
#include <stddef.h>
int ft_strcmp(const char *s1, const char *s2)
{
size_t i;
i = 0;
while (s1[i] && s1[i] == s2[i])
i++;
return ((unsigned char) s1[i] - (unsigned char) s2[i]);
}