-
Notifications
You must be signed in to change notification settings - Fork 8
/
more_fun.c
110 lines (100 loc) · 1.52 KB
/
more_fun.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
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
107
108
109
110
#include "shell.h"
/**
* _strcpy - Copie Source To Destination Char
* @dest:Destination
* @src:Source
* Return: Copie Of Char *
*/
char *_strcpy(char *dest, char *src)
{
int i;
i = 0;
while (src[i])
{
dest[i] = src[i];
i++;
}
dest[i] = '\0';
return (dest);
}
/**
* _strcat - Concat Two String
* @dest:First String
* @src:Second String
* Return:First String + Second String Char *
*/
char *_strcat(char *dest, char *src)
{
char *s = dest;
while (*dest != '\0')
{
dest++;
}
while (*src != '\0')
{
*dest = *src;
dest++;
src++;
}
*dest = '\0';
return (s);
}
/**
* _strchr - Locate Charactere In String
* @s:String Search In
* @c:Char To Search For
* Return: Pointer To Char*
*/
char *_strchr(char *s, char c)
{
do {
if (*s == c)
{
break;
}
} while (*s++);
return (s);
}
/**
* _strncmp - Compare Amount (n) Of Characters Of Two Strings.
* @s1: A String.
* @s2: A String.
* @n: Amount Of Characters To Compare.
*
* Return: 1 If The Strings Don't Match Otherwise 0
*/
int _strncmp(const char *s1, const char *s2, size_t n)
{
size_t i;
if (s1 == NULL)
return (-1);
for (i = 0; i < n && s2[i]; i++)
{
if (s1[i] != s2[i])
{
return (1);
}
}
return (0);
}
/**
* _strdup - Duplicate A String
* @str:String
* Return: Duplicate String Failed Null
*/
char *_strdup(char *str)
{
size_t len, i;
char *str2;
len = _strlen(str);
str2 = malloc(sizeof(char) * (len + 1));
if (!str2)
{
return (NULL);
}
for (i = 0; i <= len; i++)
{
str2[i] = str[i];
}
return (str2);
}