-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstr_func.c
94 lines (82 loc) · 1.43 KB
/
str_func.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
#include "shell.h"
/**
* _strlen - a function that checks length of a string
* @s: pointer to the string
* Return: integer value of string length
*/
int _strlen(char *s)
{
int l = 0;
while (*s++)
{
l++;
}
return (l);
}
/**
* _strcat - a function that concatenates two strings
* @dest: string to receive string
* @src: string to send string to dest
* Return: dest string
*/
char *_strcat(char *dest, char *src)
{
int i = 0, j = 0;
while (dest[i] != '\0')
i++;
while (src[j] != '\0')
{
dest[i] = src[j];
i++;
j++;
}
dest[i] = '\0';
return (dest);
}
/**
* _strcmp - a function comparing string values
* @s1: first string
* @s2: second string
* Return: 0 always a success
*/
int _strcmp(char *s1, char *s2)
{
int i = 0;
while (s1[i] != '\0' && s2[i] != '\0')
{
if (s1[i] != s2[i])
return (s1[i] - s2[i]);
i++;
}
return (0);
}
/**
* _strcpy - a fucntion that copies src to dest
* @dest: string to receive copy
* @src: string to send copy
* Return: copied string
*/
char *_strcpy(char *dest, char *src)
{
int l = 0, x;
while (*(src + l) != '\0')
l++;
for (x = 0; x < l; x++)
dest[x] = src[x];
dest[l] = '\0';
return (dest);
}
/**
* _strdup - a function that duplicates a string
* @str: parameter for the string to be duplicated
* Return: the duplicate
*/
char *_strdup(const char *str)
{
char *dup;
dup = malloc(strlen(str) + 1);
if (dup == NULL)
return (NULL);
strcpy(dup, str);
return (dup);
}