-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstring_operations.c
More file actions
110 lines (93 loc) · 1.72 KB
/
Copy pathstring_operations.c
File metadata and controls
110 lines (93 loc) · 1.72 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include "shell.h"
/**
* free_string - Frees memory allocated for an array of strings.
*
* @string_array: A pointer to an array of strings.
*
* Description: This function iterates through the array of strings, frees each
* string, and then frees the array itself. It also sets the pointer to NULL to
* prevent dangling references.
*/
void free_string(char ***string_array)
{
int i = 0;
char **array;
if (string_array == NULL || (*string_array) == NULL)
return;
array = *string_array;
for (i = 0; array[i] != NULL; i++)
{
safefree(array[i]);
}
safefree(array);
*string_array = NULL;
}
/**
* _strncpy - Copies up to n characters from the source string to the
* destination.
*
* @dest: The destination string.
*
* @src: The source string.
*
* @n: The maximum number of characters to copy.
*
* Return: A pointer to the destination string.
*/
char *_strncpy(char *dest, const char *src, int n)
{
int i = 0;
while (i < n && src[i] != '\0')
{
dest[i] = src[i];
i++;
}
while (i < n)
{
dest[i] = '\0';
i++;
}
return (dest);
}
/**
* _isalpha - checks for alphabetic character.
*
* @c: parameter value.
*
* Return: Returns 1 if c is a letter, lowercase or uppercase.
*
*/
int _isalpha(int c)
{
if ((c >= 97 && c <= 122) || (c >= 65 && c <= 90))
{
return (1);
}
else
{
return (0);
}
return (0);
}
/**
* _strcmp - compares two strings.
*
* @s1:first string.
* @s2: second string.
*
* Return: 0 if @s1 and @s2 are equal, a negative value if @s1 is
* less than @s2, a positive value if @s1 is greater than @s2.
*/
int _strcmp(char *s1, char *s2)
{
int i = 0;
while (s1[i] != '\0' && s2[i] != '\0')
{
if (s1[i] != s2[i])
{
return (s1[i] - s2[i]);
}
i++;
}
return (0);
}