-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstring_functions.c
91 lines (79 loc) · 1.5 KB
/
string_functions.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include "shellheader.h"
/**
* _strcmp - finds if two strings are the exactly equal
* @name: string to search for
* @var: variable to compare against
* @len: length of name
* Return: 1 if strings are equal else -1
*/
int _strcmp(char *name, char *var, unsigned int len)
{
unsigned int var_length;
unsigned int i;
var_length = _stringlen(var);
if (var_length != len)
return (-1);
i = 0;
while (name[i] != '\0' && var[i] != '\0')
{
if (name[i] != var[i])
return (1);
i++;
}
return (0);
}
/**
* _stringncmp - compares two strings
* up to given length are the same
* @name: name to be compared
* @str: string to compare against
* @len: length for comparing
* Return: 1 if strings are equal, -1 if they are not
*/
int _stringncmp(char *name, char *str, unsigned int len)
{
unsigned int i;
i = 0;
while (i < len)
{
if (name[i] != str[i])
return (-1);
i++;
}
return (1);
}
/**
* *_stringcpy - copies string pointed to by src to the buffer pointed to dest
* @dest: destination for the copied string
* @src: source of the string to be copied
* Return: the pointer to dest
*/
char *_stringcpy(char *dest, char *src)
{
int i, len;
len = 0;
i = 0;
while (src[len] != '\0')
{
len++;
}
while (i < len)
{
dest[i] = src[i];
i++;
}
dest[len] = '\0';
return (dest);
}
/**
* _stringlen - returns the length of a string
* @s: string whose length will be found
* Return: string length
*/
int _stringlen(char *s)
{
int i = 0;
while (s[i] != '\0')
i++;
return (i);
}