-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strcmp.c
62 lines (55 loc) · 1.53 KB
/
ft_strcmp.c
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: danalvar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/24 21:18:33 by danalvar #+# #+# */
/* Updated: 2024/10/28 19:57:18 by danalvar ### ########.fr */
/* */
/* ************************************************************************** */
int ft_strlen(char *str)
{
int contador;
contador = 0;
while (*str != '\0')
{
contador++;
str++;
}
return (contador);
}
int ft_strcmp(char *s1, char *s2)
{
int i;
int len1;
int len2;
i = 0;
len1 = ft_strlen(s1);
len2 = ft_strlen(s2);
if (s1[i] != '\0' || s2[i] != '\0')
{
while (i < len1 || i < len2)
{
if (s1[i] != s2[i])
return (s1[i] - s2[i]);
i++;
}
}
return (0);
}
/*#include <stdio.h>
#include <string.h>
int main(void)
{
int custom;
int original;
char* s1 = "dsf";
char* s2 = "sad";
custom = ft_strcmp(s1, s2);
original = strcmp(s1, s2);
printf("Custom %i\n", custom);
printf("Original %i\n", original);
return (0);
}*/