-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_string.c
More file actions
executable file
·95 lines (80 loc) · 1.67 KB
/
_string.c
File metadata and controls
executable file
·95 lines (80 loc) · 1.67 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include "header.h"
/**
* _strlen - Returns the length of a string.
* @str: String to check its size.
*
* Return: Size of the string.
*/
int _strlen(char *str)
{
int i = 0;
if (str == NULL)
return (0);
while (str[i])
i++;
return (i);
}
/**
* _strcpy - Copies the string pointed to by src
* to the buffer pointed to by dest.
* @dest: Pointer to save the string.
* @src: String to save in dest.
*
* Return: The new string saved in dest.
*/
char *_strcpy(char *dest, char *src)
{
int c;
for (c = 0; src[c] != '\0' ; c++)
dest[c] = *(src + c);
dest[c] = *(src + c);
return (dest);
}
/**
* _strcmp - Compares two strings.
* @s1: The first string.
* @s2: The second string.
*
* Return: The difference of characters between strings. 0 if equal.
*/
int _strcmp(char *s1, char *s2)
{
while (*s1 && *s2 && (*s1 == *s2))
s1++, s2++;
return (*s1 - *s2);
}
/**
* _strncmp - Compare n amount of characters from two strings.
* @s1: The first string to compare.
* @s2: The second string to compare.
* @n: The amount of characters to compare.
*
* Return: The diference of characters between strings. 0 if equal.
*/
int _strncmp(char *s1, char *s2, int n)
{
while (*s1 && *s2 && (*s1 == *s2) && n)
s1++, s2++, n--;
if (n == 0)
return (0);
return (*s1 - *s2);
}
/**
* _atoi - Converts a string to an integer.
* @s: String to convert.
*
* Return: String number to int format.
*/
int _atoi(char *s)
{
int c, sign = 1;
unsigned int result = 0;
for (c = 0; s[c] != '\0' ; c++)
if (s[c] == '-')
sign *= -1;
else if (s[c] >= '0' && s[c] <= '9')
result = (result * 10) + (s[c] - '0');
else if (result)
break;
return (result * sign);
}