-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxstring.c
More file actions
42 lines (35 loc) · 712 Bytes
/
xstring.c
File metadata and controls
42 lines (35 loc) · 712 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
#include "main.h"
/**
* _strchr - locates a character in a given string
* @str: the given string
* @c: the given string
*
* Return: (Success) a pointer to the first occurence of c
* ------- (Fail) return a null pointer
*/
char *_strchr(char *str, char c)
{
char *ptr;
for (ptr = str; *ptr; ptr++)
if (*ptr == c)
return (ptr);
return (NULL);
}
/**
* _strdup - dupicates string
* @str: the given string
*
* Return: (Success) a pointer to the duplicated string
* ------- (Fail) return a null pointer
*/
char *_strdup(char *str)
{
char *dupl;
if (str == NULL)
return (NULL);
dupl = malloc(_strlen(str) + 1);
if (dupl == NULL)
return (NULL);
_strcpy(dupl, str);
return (dupl);
}