40 lines
1.4 KiB
C
40 lines
1.4 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_strncmp.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2023/11/07 16:56:56 by rparodi #+# #+# */
|
|
/* Updated: 2024/10/31 18:13:58 by rparodi ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "libft.h"
|
|
|
|
/**
|
|
* @brief Compares two strings up to a specified number of characters.
|
|
*
|
|
* @param s1 The first string to compare.
|
|
* @param s2 The second string to compare.
|
|
* @param n The maximum number of characters to compare.
|
|
*
|
|
* @return An integer indicating the relationship between the two strings.
|
|
*/
|
|
int ft_strncmp(const char *s1, const char *s2, size_t n)
|
|
{
|
|
size_t i;
|
|
int diff;
|
|
|
|
i = 0;
|
|
while ((s1[i] || s2[i]) && i < n)
|
|
{
|
|
if (s1[i] != s2[i])
|
|
{
|
|
diff = (unsigned char)s1[i] - (unsigned char)s2[i];
|
|
return (diff);
|
|
}
|
|
i++;
|
|
}
|
|
return (0);
|
|
}
|