-
Notifications
You must be signed in to change notification settings - Fork 1
/
exits.c
76 lines (68 loc) · 1.14 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
75
76
#include "shell.h"
/**
* _strncpy - 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;
char *s = dest;
i = 0;
while (i < n - 1 && src[i] != '\0')
{
dest[i] = src[i];
i++;
}
if (i < n)
{
int j = i;
while (j < n)
{
dest[j] = '\0';
j++;
}
}
return (s);
}
/**
* *_strncat - 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 (j < n && src[j] != '\0')
{
dest[i] = src[j];
i++;
j++;
}
if (j < n)
dest[i] = '\0';
return (s);
}
/**
* *_strchr - locates a character in a string
* @s: the string to be parsed
* @c: the character to look for
* Return: (s) a pointer to the memory area s
*/
char *_strchr(char *s, char c)
{
do {
if (*s == c)
return (s);
} while (*s++ != '\0');
return (NULL);
}