forked from kevin-gatimu/simple_shell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring.c
More file actions
102 lines (87 loc) · 1.4 KB
/
string.c
File metadata and controls
102 lines (87 loc) · 1.4 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
#include "holberton.h"
/**
* _strcmpdir - compares strings to find dir.
*
* @s1: string.
* @s2: string.
*
* Return: if match and any other number if otherwise.
**/
int _strcmpdir(char *s1, char *s2)
{
int i = 0;
for (; (*s2 != '\0' && *s1 != '\0') && *s1 == *s2; s1++)
{
if (i == 3)
break;
i++;
s2++;
}
return (*s1 - *s2);
}
/**
* charput - writes the character like putchar
* @c: The character to print
*
* Return: On success 1.
* On error, -1 is returned, and errno is set appropriately.
*/
int charput(char c)
{
return (write(1, &c, 1));
}
/**
* place - similar to puts in C
* @str: a pointer the integer we want to set to 402
*
* Return: int
*/
void place(char *str)
{
while (*str != '\0')
{
charput(*str);
str++;
}
}
/**
* _strlen - Len string.
* @str: My string.
* Return: Length.
*/
int _strlen(char *str)
{
int i;
for (i = 0; str[i] != '\0'; i++)
;
return (i);
}
/**
* str_concat - concatane strings.
* @s1: string.
* @s2: second string.
* Return: strings.
*/
char *str_concat(char *s1, char *s2)
{
char *a;
int lens1, lens2, j, i, e;
if (s1 == NULL)
s1 = "";
if (s2 == NULL)
s2 = "";
lens1 = _strlen(s1);
lens2 = _strlen(s2);
a = malloc(((lens1) + (lens2) + 1) * sizeof(char));
if (a == NULL)
return (NULL);
for (j = 0; j < lens1; j++)
{
a[j] = s1[j];
}
for (i = lens1, e = 0; e <= lens2; i++, e++)
{
a[i] = s2[e];
}
return (a);
}