-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strncmp.c
More file actions
41 lines (35 loc) · 1.51 KB
/
Copy pathft_strncmp.c
File metadata and controls
41 lines (35 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* strncmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dramos-h <dramos-h@student.42urduli> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/30 12:48:47 by dramos-h #+# #+# */
/* Updated: 2022/11/30 12:48:48 by dramos-h ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_strncmp(const char *s1, const char *s2, size_t n)
{
size_t i;
i = 0;
while (i < n && (s1[i] || s2[i]))
{
if (s1[i] != s2[i])
return (((unsigned char *)s1)[i] - ((unsigned char *)s2)[i]);
i++;
}
return (0);
}
/* int main ()
{
size_t n = 11;
const char *s1 = "Hola Mundo";
const char *s2 = "Hola Mund";
printf("%d\n", ft_strncmp(s1, s2, n));
} */
/* Sirve para comparar n caracteres entre cadena2 y
cadena1 . Devuelve el valor devuelve 0 si son iguales.
Devuelve menor que cero si cadena1 es menor que cadena2 .
Devuelve mayor que cero si cadena1 es mayor que cadena2*/