-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexit.c
64 lines (55 loc) · 1.19 KB
/
exit.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
#include "shell.h"
/**
* _strncpy - This will 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, const char *src, size_t n)
{
size_t i;
for (i = 0; i < n && src[i] != '\0'; i++)
dest[i] = src[i];
for ( ; i < n; i++)
dest[i] = '\0';
return dest;
}
/**
* _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, const char *src, size_t n)
{
size_t dest_len = strlen(dest);
size_t i;
for (i = 0; i < n && src[i] != '\0'; i++)
dest[dest_len + i] = src[i];
dest[dest_len + i] = '\0';
return dest;
}
/**
* _strchr - This will locates a character in a string
* @s: the string to be parsed
* @c: the character to look for
*
* Return: a pointer to the first occurrence of the character c in s,
* or NULL if the character is not found
*/
char *_strchr(const char *s, int c)
{
while (*s)
{
if (*s == c)
return (char *)s;
s++;
}
if (*s == c)
return (char *)s;
return NULL;
}