-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstr-funct3.c
74 lines (68 loc) · 1.18 KB
/
str-funct3.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: it copies a string from 1 distination to another
*dest: the destination of the string to be copied to
*src:source of the string
*n: the amount of characters that should be copied
*Return: the concatenated string
*/
char *_strncpy(char *dest, char *src, int n)
{
int z, k;
char *f = dest;
z = 0;
while (src[z] != '\0' && z < n - 1)
{
dest[z] = src[z];
z++;
}
if (z < n)
{
k = z;
while (k < n)
{
dest[k] = '\0';
k++;
}
}
return (f);
}
/**
*_strncat: it concatenates two strings
*league: the first string
*legend: the second string
*n: the amount of bytes to be max used
*Return: the concatenated string
*/
char *_strncat(char *league, char *legend, int n)
{
int z, k;
char *f = league;
z = 0;
k = 0;
while (league[z] != '\0')
z++;
while (legend[k] != '\0' && k < n)
{
league[z] = legend[k];
z++;
k++;
}
if (k < n)
league[z] = '\0';
return (f);
}
/**
*_strchr: it locates the character in a string
*f:string to be parsed
*l:character to look for
*Return: (f) a pointer to the memory area f
*/
char *_strchr(char *f, char l)
{
do {
if (*f == l)
return (f);
} while (l++ != '\0');
return (NULL);
}