Repository navigation
Expand file tree
/
Copy pathstring_functions1.c
More file actions
executable file
·87 lines (74 loc) · 2 KB
/
Copy pathstring_functions1.c
File metadata and controls
executable file
·87 lines (74 loc) · 2 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
80
81
82
83
84
85
86
87
#include "shell.h"
int string_length(const char *s);
char *_stringcat(char *destination, const char *source);
char *_stringcopy(char *destination, const char *source);
char *_strncat(char *destination, const char *source, size_t n);
/**
* string_length - Returns the length of a string.
* @s: A pointer to the characters string.
*
* Return: The length of the character string.
*/
int string_length(const char *s)
{
int length = 0;
if (!s)
return (length);
for (length = 0; s[length]; length++)
;
return (length);
}
/**
* _stringcat - Concantenates two strings.
* @destination: Pointer to destination string.
* @source: Pointer to source string.
*
* Return: Pointer to destination string.
*/
char *_stringcat(char *destination, const char *source)
{
const char *srcTemp;
char *destTemp;
destTemp = destination;
srcTemp = source;
while (*destTemp != '\0')
destTemp++;
while (*srcTemp != '\0')
*destTemp++ = *srcTemp++;
*destTemp = '\0';
return (destination);
}
/**
* _stringcopy - Copies the string pointed to by source, including the
* terminating null byte, to the buffer pointed by des.
* @destination: Pointer to the destination of copied string.
* @source: Pointer to the source of the source string.
*
* Return: Pointer to destination.
*/
char *_stringcopy(char *destination, const char *source)
{
size_t i;
for (i = 0; source[i] != '\0'; i++)
destination[i] = source[i];
destination[i] = '\0';
return (destination);
}
/**
* _strncat - Concantenates two strings where n number
* of bytes are copied from source.
* @destination: Pointer to destination string.
* @source: Pointer to source string.
* @n: n bytes to copy from source.
*
* Return: Pointer to destination string.
*/
char *_strncat(char *destination, const char *source, size_t n)
{
size_t dest_length = string_length(destination);
size_t i;
for (i = 0; i < n && source[i] != '\0'; i++)
destination[dest_length + i] = source[i];
destination[dest_length + i] = '\0';
return (destination);
}