-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile.c
More file actions
44 lines (39 loc) · 774 Bytes
/
file.c
File metadata and controls
44 lines (39 loc) · 774 Bytes
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
#include "shell.h"
/**
* _strstr - locates a substring.
* @haystack: string to search in
* @needle: substring to look for
*
* Return: pointer to the beginning of the located
* substring or NULL if not found
*/
char *_strstr(char *haystack, char *needle)
{
int i, j;
for (i = 0; haystack[i] != '\0'; i++)
{
for (j = 0; needle[j] != '\0'; j++)
{
if (haystack[i + j] != needle[j])
break;
}
if (!needle[j])
return (&(haystack[i + _strlen(needle) + 1]));
}
return (NULL);
}
/**
* putstream - a function that prints to stdout
* @str: input string to print
* @stream: where to print the string
*
* Return: a single character.
*/
void putstream(char *str, int stream)
{
while (*str != '\0')
{
write(stream, str, 1);
str++;
}
}