Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
yabtaour
GitHub Repository: yabtaour/Minishell-42
Path: blob/main/utils/ft_strcmp.c
1407 views
1
/* ************************************************************************** */
2
/* */
3
/* ::: :::::::: */
4
/* ft_strcmp.c :+: :+: :+: */
5
/* +:+ +:+ +:+ */
6
/* By: yabtaour <[email protected]> +#+ +:+ +#+ */
7
/* +#+#+#+#+#+ +#+ */
8
/* Created: 2022/07/26 18:12:27 by yabtaour #+# #+# */
9
/* Updated: 2022/07/26 18:12:41 by yabtaour ### ########.fr */
10
/* */
11
/* ************************************************************************** */
12
13
#include "../minishell.h"
14
15
int ft_strcmp(char *s1, char *s2)
16
{
17
int i;
18
int j;
19
20
i = 0;
21
while (s1 [i] != '\0' && s2 [i] != '\0' && s1[i] == s2[i])
22
i++;
23
if (s1 == s2)
24
j = 0;
25
else
26
j = s1 [i] - s2 [i];
27
return (j);
28
}
29
30
int ft_strncmp(char *s1, char *s2, size_t n)
31
{
32
size_t i;
33
34
i = 0;
35
while (i < n)
36
{
37
if (s1[i] != s2[i])
38
return ((unsigned char)s1[i] - (unsigned char)s2[i]);
39
if (s1[i] == '\0' && s2[i] == '\0')
40
return (0);
41
i++;
42
}
43
return (0);
44
}
45
46