-
Notifications
You must be signed in to change notification settings - Fork 0
/
stronc.c
74 lines (68 loc) · 940 Bytes
/
stronc.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 "main.h"
/**
**_strncpy - it copy a str
*@dest: destinatio
*@src: str
*@n: amount of chars
*Return: s
*/
char *_strncpy(char *dest, char *src, int n)
{
int i, p;
char *s = dest;
i = 0;
while (src[i] != '\0' && i < n - 1)
{
dest[i] = src[i];
i++;
}
if (i < n)
{
p = i;
while (p < n)
{
dest[p] = '\0';
p++;
}
}
return (s);
}
/**
**_strncat - it concat two str
*@dest: first one
*@src: second str
*@n: amount
*Return: s
*/
char *_strncat(char *dest, char *src, int n)
{
int i, p;
char *s = dest;
i = 0;
p = 0;
while (dest[i] != '\0')
i++;
while (src[p] != '\0' && p < n)
{
dest[i] = src[p];
i++;
p++;
}
if (p < n)
dest[i] = '\0';
return (s);
}
/**
**_strchr - it locates a char
*@s: str
*@c: char
*Return: it returns (s) a pointer to memory area s
*/
char *_strchr(char *s, char c)
{
do {
if (*s == c)
return (s);
} while (*s++ != '\0');
return (NULL);
}