-
Notifications
You must be signed in to change notification settings - Fork 0
/
exits.c
74 lines (68 loc) · 1.12 KB
/
exits.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
#include "shell.h"
/**
* Copies a string.
* @dest: The destination string to be copied to.
* @src: The source string.
* @n: The amount of characters to be copied.
* Return: The concatenated string.
*/
char *_strncpy(char *dest, char *src, int n)
{
int i, j;
char *s = dest;
i = 0;
while (src[i] != '\0' && i < n - 1)
{
dest[i] = src[i];
i++;
}
if (i < n)
{
j = i;
while (j < n)
{
dest[j] = '\0';
j++;
}
}
return (s);
}
/**
* Concatenates two strings.
* @dest: The first string.
* @src: The second string.
* @n: The amount of bytes to be maximally used.
* Return: The concatenated string.
*/
char *_strncat(char *dest, char *src, int n)
{
int i, j;
char *s = dest;
i = 0;
j = 0;
while (dest[i] != '\0')
i++;
while (src[j] != '\0' && j < n)
{
dest[i] = src[j];
i++;
j++;
}
if (j < n)
dest[i] = '\0';
return (s);
}
/**
* Locates a character in a string.
* @s: The string to be parsed.
* @c: The character to look for.
* Return: A pointer to the memory area s.
*/
char *_strchr(char *s, char c)
{
do {
if (*s == c)
return (s);
} while (*s++ != '\0');
return (NULL);
}