-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstr_func4.c
More file actions
87 lines (83 loc) · 1.31 KB
/
str_func4.c
File metadata and controls
87 lines (83 loc) · 1.31 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
#include "shell.h"
/**
* our_lengthstr - to get the length of string
* @str: string
* Return: length
*/
int our_lengthstr(char *str)
{
int counter = 0;
if (!str)
return (0);
while (*str++)
counter++;
return (counter);
}
/**
* our_compStr - like strcmp function
* @ptr1: string No.1
* @ptr2: string No.
* Return: -1 or 1 or 0
*/
int our_compStr(char *ptr1, char *ptr2)
{
while (*ptr1 && *ptr2)
{
if (*ptr1 != *ptr2)
return (*ptr1 - *ptr2);
ptr1++;
ptr2++;
}
if (*ptr1 == *ptr2)
return (0);
else
return (*ptr1 < *ptr2 ? -1 : 1);
}
/**
* pointOfSt - haystack checking
* @H: checking string
* @N: the required string
* Return: pointer
*/
char *pointOfSt(const char *H, const char *N)
{
while (*N)
if (*N++ != *H++)
return (NULL);
return ((char *)H);
}
/**
* our_catStr - like strcat function
* @BD: Buffer destin.
* @BS: Buffer source
* Return: address
*/
char *our_catStr(char *BD, char *BS)
{
char *a = BD;
while (*BD)
BD++;
while (*BS)
*BD++ = *BS++;
*BD = *BS;
return (a);
}
/**
* our_CpyStr - like strcpy function
* @BD: Buffer destin.
* @BS: Buffer source
* Return: address
*/
char *our_CpyStr(char *BD, char *BS)
{
int count = 0;
if ((BD == BS) || (BS == 0))
return (BD);
while (BS[count])
{
BD[count] = BS[count];
count++;
}
BD[count] = 0;
return (BD);
}