Skip to content

Commit f0f4252

Browse files
Code: added code for 3-strcmp.c
1 parent 4499af0 commit f0f4252

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed
+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#include "main.h"
2+
3+
/**
4+
* _strcmp - A function that compares two strings
5+
*
6+
* @s1: The first string
7+
* @s2: The second string
8+
*
9+
* Return: int value
10+
*/
11+
12+
int _strcmp(char *s1, char *s2)
13+
{
14+
int a = 0, b = 0, c = 0, r = 0, lim;
15+
16+
while (s1[a])
17+
{
18+
a++;
19+
}
20+
21+
while (s2[b])
22+
{
23+
b++;
24+
}
25+
26+
if (a <= b)
27+
{
28+
lim = a;
29+
}
30+
else
31+
{
32+
lim = b;
33+
}
34+
35+
while (c <= lim)
36+
{
37+
if (s1[c] == s2[c])
38+
{
39+
c++;
40+
continue;
41+
}
42+
else
43+
{
44+
r = s1[c] - s2[c];
45+
break;
46+
}
47+
48+
c++;
49+
}
50+
51+
return (r);
52+
}

0 commit comments

Comments
 (0)