-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstring_functions.c
95 lines (85 loc) · 1.33 KB
/
string_functions.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
#include "holberton.h"
/**
* _strlen - find length of string
* @s: input string
* Return: length integer
*/
int _strlen(const char *s)
{
int i = 0;
while (s[i] != '\0')
{
i++;
}
return (i);
}
/**
* _strcpy - copy strings
* @dest: destnation output
* @src: src input
* Return: destination of copied string
*/
char *_strcpy(char *dest, char *src)
{
int i;
i = 0;
while (src[i] != '\0')
{
dest[i] = src[i];
i++;
}
dest[i] = '\0';
return (dest);
}
/**
* _strcat - concatanate two strings
* @dest: destination output
* @src: src input
* Return: concatonated strings
*/
char *_strcat(char *dest, char *src)
{
int i, j;
i = 0;
j = 0;
/* gets the length of src string*/
while (dest[i] != '\0')
{
i++;
}
dest[i] = '/';
i++;
while (src[j] != '\0')
{
dest[i] = src[j];
j++;
i++;
}
dest[i] = '\0';
return (dest);
}
/**
* _strdup - returns a copy of a string passed
* @str: string passed
(* a blank line
* Description: Longer description of the function)?
(* section header: Section description)*
* Return: return copy string, NULL otherwise
*/
char *_strdup(const char *str)
{
int len, i;
char *a;
if (str == NULL)
return (NULL);
len = _strlen(str);
a = malloc(len * sizeof(char) + 1);
if (a == NULL)
return (NULL);
for (i = 0; i < len; i++)
{
a[i] = str[i];
}
a[i] = '\0';
return (a);
}