-
Notifications
You must be signed in to change notification settings - Fork 0
/
str_create.c
74 lines (68 loc) · 1.2 KB
/
str_create.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
#include "shell.h"
/**
* join_str - concatenates string 1 + string 2
* @s1: string 1
* @s2: string 2
* Return: copy of string with null terminated char
*/
char *join_str(char const *s1, char const *s2)
{
size_t l3;
char *s3;
if (!s1 || !s2)
return (NULL);
l3 = strlen(s1) + strlen(s2);
s3 = malloc(l3 + 1);
if (s3 == NULL)
return (NULL);
s3[0] = '\0';
strcat(s3, s1);
strcat(s3, s2);
s3[l3] = '\0';
return (s3);
}
/**
* strsub_f - function that substract a paragraph from string
* @s: string
* @start: index of start
* @len: len of characters to do a copy
* Return: copy of string with null terminated char
*/
char *strsub_f(char const *s, unsigned int start, size_t len)
{
size_t i;
char *us;
us = (char *)malloc(len + 1);
if (s == NULL || us == NULL)
return (NULL);
i = 0;
while (len-- && s[start + i])
{
us[i] = s[start + i];
i++;
}
us[i] = '\0';
return (us);
}
/**
* f_memdel - function that free an array
* @ap: array of strings
* Return: void
*/
void f_memdel(void **ap)
{
if (ap)
{
free(*ap);
*ap = NULL;
}
}
/**
* strdel_f - function that delete an array of strings
* @as: array of strings
* Return: void
*/
void strdel_f(char **as)
{
f_memdel((void **)as);
}