ft_strncmp: initial implementation
This commit is contained in:
parent
10cf338cbf
commit
b176bdaebe
3 changed files with 53 additions and 3 deletions
48
ft_strncmp.c
Normal file
48
ft_strncmp.c
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strncmp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: kcolin <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/16 13:23:17 by kcolin #+# #+# */
|
||||
/* Updated: 2024/10/16 13:44:38 by kcolin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_strncmp(const char *s1, const char *s2, t_size n)
|
||||
{
|
||||
t_size i;
|
||||
|
||||
i = 0;
|
||||
while (s1[i] != '\0' && s2[i] != 0)
|
||||
{
|
||||
if (i >= n)
|
||||
return (0);
|
||||
if (s1[i] != 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)
|
||||
{
|
||||
t_size cmp_len;
|
||||
|
||||
cmp_len = 9;
|
||||
if (argc > 2)
|
||||
{
|
||||
printf("mine: %d\tlib: %d\n",
|
||||
ft_strncmp(argv[1], argv[2], cmp_len),
|
||||
strncmp(argv[1], argv[2], cmp_len));
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
*/
|
||||
Loading…
Add table
Add a link
Reference in a new issue