-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmyFuncs.c
More file actions
112 lines (99 loc) · 2.12 KB
/
myFuncs.c
File metadata and controls
112 lines (99 loc) · 2.12 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
111
112
#include "holberton.h"
/**
* _memset - recreates the memset funtion
*
* Description: copies the value of c into n characters pointed at s
* @s: points to the place in memory to write to
* @b: what you want to replace it with
* @n: number of characters to be replaced
* Return: returns the pointer
*/
char *_memset(char *s, char b, unsigned int n)
{
int i = 0;
while (n--)
{
s[i] = b;
i++;
}
return (s);
}
/**
* _strcat - concatenates two strings
*
* Description: finds the end of a strings and copies the string from there
* @dest: destination array
* @src: sourse array
* Return: returns the destination file
*/
char *_strcat(char *dest, char *src)
{
int i, j;
i = 0;
while (dest[i] != '\0')
i++;
for (j = 0 ; src[j] != '\0' ; j++, i++)
{
dest[i] = src[j];
}
dest[i] = '\0';
return (dest);
}
/**
* _strcpy - copys array from one pointer to another
*
* Description: loops through array and copies each element
* @dest: pointer to destination file
* @src: pointer to source file
* Return: the array
*/
char *_strcpy(char *dest, char *src)
{
int i = 0;
while (src[i] != '\0')
{
dest[i] = src[i];
i++;
}
dest[i] = src[i];
return (dest);
}
/**
* _strlen - prints the length of a string
* Description: cycles through the array of s until its false
* @s: input from file
* Return: returns the length
*/
int _strlen(char *s)
{
int counter = 0;
/* initialize a counter for the length */
while (s[counter] != 0) /*uses s to create an array for the input*/
counter++; /*counts every element*/
return (counter); /*return end counter8*/
}
/**
* _strstr - locates a substring in a string
*
* Description: finds the matching bytes of substring in string
* @haystack: pointer to the string to search in
* @needle: pointer to the substring of searched for bytes
* Return: the matched bytes otherwise null
*/
char *_strstr(char *haystack, char *needle)
{
while (*haystack)
{
char *Begin = haystack;
char *pattern = needle;
while (*haystack && *pattern && *haystack == *pattern)
{
haystack++;
pattern++;
}
if (!*pattern)
return (Begin);
haystack = Begin + 1;
}
return (0);
}