-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrfunctions.c
More file actions
106 lines (88 loc) · 1.51 KB
/
strfunctions.c
File metadata and controls
106 lines (88 loc) · 1.51 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include "holberton.h"
/**
* _strlen - returns the length of a string
* @s: char array pointer
* Return: On success 1.
* On error, -1 is returned, and errno is set appropriately.
*/
int _strlen(const char *s)
{
int i = 0;
while (s[i] != '\0')
{
i++;
}
return (i);
}
/**
* *_strncat - concatenate strings
* @dest: array
* @src: array
* @n: numers os bytes to concatenate
* Return: Always 0.
*/
char *_strncat(char *dest, char *src, int n)
{
int i, j;
for (i = 0; dest[i] != '\0'; i++)
;
for (j = 0; j < n && src[j] != '\0'; j++)
dest[i + j] = src[j];
dest[i + j] = '\0';
return (dest);
}
/**
* *_strcpy - reverses a string
* @dest: char array destiny
* @src: array in
* Return: On success 1.
* On error, -1 is returned, and errno is set appropriately.
*/
char *_strcpy(char *dest, char *src)
{
int i = 0;
while (src[i] != '\0')
{
dest[i] = src[i];
i++;
}
dest[i] = src[i];
return (src);
}
/**
* _strcmp - compare strings
* @s1: array
* @s2: array
* Return: Always 0.
*/
int _strcmp(char *s1, char *s2)
{
int i = 0;
while ((s1[i] == s2[i]) && (s1[i] != '\0') && (s2[i] != '\0'))
i++;
return (s1[i] - s2[i]);
}
/**
* *_strdup - create array
* @str: input array
* Return: null in error
*/
char *_strdup(char *str)
{
int i = 0, size = 0;
char *str_;
if (str == NULL)
return (NULL);
while (*(str + size))
size++;
size++;
str_ = malloc(sizeof(char) * size);
if (str_ == NULL)
return (NULL);
while (i < size)
{
*(str_ + i) = *(str + i);
i++;
}
return (str_);
}