-
Notifications
You must be signed in to change notification settings - Fork 3
/
exit_shell.c
74 lines (68 loc) · 1.1 KB
/
exit_shell.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"
/**
**_strncpy - functions that copies a string
*@desti: destination string
*@srce: source string
*@m: no of characters to be copied
*Return: concat string
*/
char *_strncpy(char *desti, char *srce, int m)
{
int l, k;
char *s = desti;
l = 0;
while (srce[l] != '\0' && l < m - 1)
{
desti[l] = srce[l];
l++;
}
if (l < m)
{
k = l;
while (k < m)
{
desti[k] = '\0';
k++;
}
}
return (s);
}
/**
**_strncat - function that concatenates two strings
*@dest: first string
*@src: second string
*@m: the no of bytes to be used
*Return: concatenated string
*/
char *_strncat(char *dest, char *src, int m)
{
int l, k;
char *s = dest;
l = 0;
k = 0;
while (dest[l] != '\0')
l++;
while (src[k] != '\0' && k < m)
{
dest[l] = src[k];
l++;
k++;
}
if (k < m)
dest[l] = '\0';
return (s);
}
/**
**_strchr - function that locates a character in a string
*@str: the string parsed
*@d: character
*Return: (str) ptr to memory area
*/
char *_strchr(char *str, char d)
{
do {
if (*str == d)
return (str);
} while (*str++ != '\0');
return (NULL);
}