-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strchr.c
39 lines (37 loc) · 1.62 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
39
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: imunaev- <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/06 13:39:36 by imunaev- #+# #+# */
/* Updated: 2025/01/18 12:38:55 by imunaev- ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/**
* @brief Locates the first occurrence of a character in a string.
*
* This function searches for the first occurrence of the character `c`
* in the string `s`. The null-terminator character `\0` is considered part
* of the string, so `c` can also be `\0` to locate the end of the string.
*
* @param s The string to search in.
* @param c The character to locate, passed as an `int` but interpreted
* as `char`.
* @return char* A pointer to the first occurrence of the character `c`
* in the string `s`, or NULL if the character is not found.
*/
char *ft_strchr(const char *s, int c)
{
while (*s != '\0')
{
if (*s == (char)c)
return ((char *)s);
s++;
}
if (!(char)c)
return ((char *)s);
return (NULL);
}