-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathutility_functions.c
More file actions
80 lines (70 loc) · 1.49 KB
/
Copy pathutility_functions.c
File metadata and controls
80 lines (70 loc) · 1.49 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include "holberton.h"
/**
* _strcmp - compares two strings to find out if they are exactly the same
* @name: name supplied by user to search for
* @variable: variable to compare against
* @length: length of name
* Return: 1 if strings are equal, -1 if they are not
*/
int _strcmp(char *name, char *variable, unsigned int length)
{
unsigned int var_length;
unsigned int i;
var_length = _strlen(variable);
if (var_length != length)
return (-1);
i = 0;
while (name[i] != '\0' && variable[i] != '\0')
{
if (name[i] != variable[i])
return (1);
i++;
}
return (0);
}
/**
* _strncmp - compares two strings
* up to given length are the same
* @name: name supplied by user to search for
* @variable: variable to compare against
* @length: length to compare up to
* Return: 1 if strings are equal, -1 if they are not
*/
int _strncmp(char *name, char *variable, unsigned int length)
{
unsigned int i;
i = 0;
while (i < length)
{
if (name[i] != variable[i])
return (-1);
i++;
}
return (1);
}
/**
* *_strcpy - copies string pointed to by src to the buffer pointed to dest
* @dest: string destination
* @src: string source
* Return: the pointer to dest
*/
char *_strcpy(char *dest, char *src)
{
int i;
int j = _strlen(src);
for (i = 0; i <= j; i++)
dest[i] = src[i];
return (dest);
}
/**
* _strlen - returns the length of a string
* @s: string to be evaluated
* Return: length of string
*/
int _strlen(char *s)
{
int i = 0;
while (s[i] != '\0')
i++;
return (i);
}