-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strchr.c
49 lines (40 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fcorvaro <fcorvaro@student.42roma.it> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/19 09:54:33 by fcorvaro #+# #+# */
/* Updated: 2023/04/18 15:15:54 by fcorvaro ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strchr(const char *str, int c)
{
int i;
i = 0;
while (str[i])
{
if (str[i] == (char)c)
return ((char *)&str[i]);
i++;
}
if (str[i] == (char)c)
return ((char *)&str[i]);
return (0);
}
/*This returns a pointer to the first occurrence of the character
c in the string str, or NULL if the character is not found.
the code below is used to test the function
#include <stdio.h>
int main ()
{
const char str[] = "daje roma daje";
const char ch = 'm';
char *res;
res = ft_strchr(str, ch);
printf("String after %c is -> %s\n", ch, res);
return(0);
}
*/