-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSS_exits.c
More file actions
80 lines (67 loc) · 1.34 KB
/
SS_exits.c
File metadata and controls
80 lines (67 loc) · 1.34 KB
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
77
78
79
#include "shell.h"
/**
* _strncpy - this function copies a string from it source to it destination
* @dest: function parameter indicating the destination of the string
* @src: function parameter showing the source of the string
* @n: parameter of the number of the char to be copied
* Return: 0 if successful
*/
char *_strncpy(char *dest, char *src, int n)
{
int a = 0;
int b;
char *c = dest;
while (src[a] != '\0' && a < n - 1)
{
dest[a] = src[a];
a++;
}
if (a < n)
{
b = a;
while (b < n)
{
dest[b] = '\0';
b++;
}
}
return (c);
}
/**
* _strncat - this function concatenate two string
* @dest: parameter showing the dest of the file
* @src: parameter showing the source of the string
* @n: the number of string to be copied
* Return: 0 if successful
*/
char *_strncat(char *dest, char *src, int n)
{
char *c = dest;
int a = 0;
int b = 0;
while (dest[a] != '\0')
a++;
while (src[b] != '\0' && b < n)
{
dest[a] = src[b];
a++;
b++;
}
if (b < n)
dest[a] = '\0';
return (c);
}
/**
* _strchr - this function searches for the first occurence of a character
* @s: parameter showing the string to be parsed
* @c: parameter showing the character to be searched
* Return: 0 if successful
*/
char *_strchr(char *s, char c)
{
do {
if (*s == c)
return (s);
} while (*s++ != '\0');
return (NULL);
}