-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbasics.c
More file actions
105 lines (100 loc) · 1.7 KB
/
Copy pathbasics.c
File metadata and controls
105 lines (100 loc) · 1.7 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
#include "holberton.h"
/**
* _strcpy - function copy the string pointed
* @dest: destination pointer
* @src: source ponter
* Return: destination pointer
*/
char *_strcpy(char *dest, char *src)
{
int cont = 0;
do {
*(dest + cont) = *(src + cont);
cont++;
} while (*(src + cont - 1) != '\0');
return (dest);
}
/**
* _strlen - Calculate size of string
* @s: string to becalculated
* Return: size of string
*/
int _strlen(char *s)
{
int cont = 0;
while (*(s + cont) != '\0')
cont++;
return (cont);
}
/**
*str_concat - Duplicate string
*@s1: string one
*@s2: string two
* Return: pointer to copy array
*/
char *str_concat(char *s1, char *s2)
{
char *p;
unsigned int i;
unsigned int size_s1, size_s2;
if (s1 == NULL)
s1 = "";
if (s2 == NULL)
s2 = "";
for (size_s1 = 0; *(s1 + size_s1) && s1; size_s1++)
{
}
for (size_s2 = 0; *(s2 + size_s2) && s2; size_s2++)
{
}
p = malloc(sizeof(char) * (size_s1 + size_s2 + 1));
if (p == NULL)
return (NULL);
for (i = 0; i < size_s1 + size_s2; i++)
{
if (i < size_s1)
p[i] = *(s1 + i);
else
p[i] = *(s2 + i - size_s1);
}
p[i] = '\0';
return (p);
}
/**
* print_number - print number in standar output
* @number: number to print
*/
void print_number(int number)
{
if (number > 9)
{
print_number(number / 10);
print_number(number % 10);
}
else
{
char n = number + '0';
write(STDOUT_FILENO, &n, 1);
}
}
/**
* _str_cmp - compare two strings
* @str1: string 1
* @str2: string 2
* Return: 1 if are equal 0 if not
*/
char _str_cmp(char *str1, char *str2)
{
if (_strlen(str1) == _strlen(str2))
{
unsigned int i = 0;
while (str1[i])
{
if (str1[i] != str2[i])
return (0);
i++;
}
return (1);
}
return (0);
}