-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring3.c
More file actions
65 lines (56 loc) · 1.39 KB
/
Copy pathstring3.c
File metadata and controls
65 lines (56 loc) · 1.39 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
#include "main.h"
/**
* _strncat - A function that concatenates two strings
* @dest: pointer to the destination of concatenated strings
* @src: pointer to the source string to concatenate
* @n: the number of bytes (characters) to concatenate
* Description: A function that concatenates two strings
* using at most n bytes from the source stringand
* then returns a pointer to the concated destination string
* Author - Ipadeola Michael Bamidele
* Return: Destination String
*/
char *_strncat(char *dest, char *src, int n)
{
int length = _strlen(dest);
int i = 0;
while (i < n && src[i] != '\0')
{
dest[length + i] = src[i];
i++;
}
dest[length + i] = '\0';
return (dest);
}
/**
* _strstr - A fxn that locates a substring
* @haystack: the main string to search from
* @needle: The substring to search from
* Description: A function that locates a substring
* finds the first occurene of a substring neglecting the
* NULL terminating bytes
* Return: A pointer to the beginning of the substring or
* NULL when no match is found
*/
char *_strstr(char *haystack, char *needle)
{
char *ptr_hay, *ptr_needle;
if (!(*needle))
{
return (haystack);
}
while (*haystack)
{
ptr_hay = haystack;
ptr_needle = needle;
while (*ptr_needle && *ptr_hay == *ptr_needle)
{
ptr_hay++;
ptr_needle++;
}
if (!(*ptr_needle))
return (haystack);
haystack++;
}
return (NULL);
}