-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstrings.c
More file actions
111 lines (92 loc) · 1.57 KB
/
strings.c
File metadata and controls
111 lines (92 loc) · 1.57 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
106
107
108
109
110
#include "shell.h"
/**
* _putchar - writes the character c to stdout
* @c: The character to print
*
* Return: On success 1.
* On error, -1 is returned, and errno is set appropriately.
*/
int _putchar(char c)
{
return (write(1, &c, 1));
}
/**
* _strlen - This function dispalys the length of
* a string
* @s: The parameter given
* Return: length;
*/
int _strlen(char *s)
{
int len = 0;
while (s[len] != '\0')
{
len++;
}
return (len);
}
/**
* _strncmp - This function compares str according to n number
* of bytes
* @str1: string one
* @str2: str 2
* @n: number of str to compare
* Return: 0, > 0 or < 0
*/
int _strncmp(const char *str1, const char *str2, size_t n)
{
size_t i;
if (str1 == NULL || str2 == NULL || n == 0)
return (0);
for (i = 0; i < n; ++i)
{
if (str1[i] != str2[i])
{
return (str1[i] - str2[i]);
}
if (str1[i] == '\0')
return (0);
}
return (0);
}
/**
* _strcmp - This function compares two str
* @s1: first str
* @s2: second str
* Return: differnce (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 (s1[i] - s2[i]);
}
/**
* _strcat - This function concatenates two pointer arguments
* @dest: destination the concated strings
* @src: parameter source to be added to dest
* Return: char
*/
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);
}