-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strchr.c
35 lines (33 loc) · 1.46 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jschott <jschott@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/05/02 14:22:52 by jschott #+# #+# */
/* Updated: 2024/08/08 11:46:56 by jschott ### ########.fr */
/* */
/* ************************************************************************** */
/**
* Searches for the first occurrence of a character in a string.
*
* @param s The string to be scanned.
* @param c The character to search for. It is an `int` which allows for EOF to be passed as a character but is
* internally treated as an `unsigned char` for comparison.
* @return A pointer to the matched character in the string, or `NULL` if the character is not found.
*/
char *ft_strchr(const char *s, int c)
{
int i;
i = 0;
while (s[i] != '\0')
{
if (s[i] == (char) c)
return ((char *) &s[i]);
i++;
}
if ((char) c == '\0')
return ((char *) &s[i]);
return (0);
}