-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strchr.c
38 lines (36 loc) · 1.74 KB
/
ft_strchr.c
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mmaurer <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/08/25 20:54:53 by mmaurer #+# #+# */
/* Updated: 2021/09/07 22:02:12 by mmaurer ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/*
* The strchr() function returns a pointer to the first occurrence of the
* character c in the string s.
* RETURN: The strchr() function return a pointer to the matched
* character or NULL if the character is not found. The terminating null byte is
* considered part of the string, so that if c is specified as '\0', these
* functions return a pointer to the terminator.
1. The ft_strchr() function takes two arguments: a string and a character.
2. The while loop runs as long as the character is not found in the string.
3. The if statement checks if the character is found in the string.
4. If the character is found, the function returns the address of the
character.
5. If the character is not found, the function returns NULL.
*/
char *ft_strchr(const char *s, int c)
{
while (*s != c)
{
if (*s == '\0')
return (NULL);
s++;
}
return ((char *)s);
}