-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrcmp.c
More file actions
48 lines (38 loc) · 736 Bytes
/
Copy pathstrcmp.c
File metadata and controls
48 lines (38 loc) · 736 Bytes
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
#include "main.h"
/**
* _strcmp - Compare two strings
* @s1: string
* @s2: string
* Return: negative int if s1 < s2, 0 if matching, and positive int if s1 > s2
*/
int _strcmp(const char *s1,const char *s2)
{
int i;
for (i = 0; s1[i] != '\0' || s2[i] != '\0'; i++)
{
if (s1[i] != s2[i])
return (s1[i] - s2[i]);
}
return (0);
}
/**
* _strdup - Duplicate a string using malloc
* @str: string to duplicate
* Return: Pointer to a the new duped string
*/
char *_strdup(char *str)
{
char *a;
int i, c;
if (str == NULL)
return (NULL);
for (i = 0; str[i] != '\0'; i++)
;
a = malloc(i * sizeof(*a) + 1);
if (a == NULL)
return (NULL);
for (c = 0; c < i; c++)
a[c] = str[c];
a[c] = '\0';
return (a);
}