Skip to content

Commit 233074c

Browse files
committed
added new question
1 parent 33f3961 commit 233074c

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

lvl2/ft_strcspn/ft_strcspn.c

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#include <string.h>
2+
3+
char find_char(const char *s, char c)
4+
{
5+
while (*s)
6+
{
7+
if (*s == c)
8+
return (1);
9+
s++;
10+
}
11+
return (0);
12+
}
13+
14+
size_t ft_strcspn(const char *s, const char *reject)
15+
{
16+
size_t i;
17+
18+
i = 0;
19+
while (s[i])
20+
{
21+
if (find_char(reject, s[i]) != 0)
22+
break ;
23+
i++;
24+
}
25+
return (i);
26+
}
27+
28+
#ifdef TEST
29+
#include <string.h>
30+
#include <stdio.h>
31+
32+
int main(void)
33+
{
34+
//char test[] = "hello world!";
35+
//char test1[] = "world!";
36+
/*char hay[] = "lol idk if i need to make my own size_t";
37+
char needle[] = "size_t";
38+
char one[] = " ";
39+
char weird[] = "1234567890";
40+
41+
printf("%lu\n", strcspn(one, weird));
42+
printf("%lu\n", ft_strcspn(one, weird));
43+
44+
printf("%lu\n", strcspn(hay, needle));
45+
printf("%lu\n", ft_strcspn(hay, needle));
46+
return (0);
47+
*/
48+
char haystack[] = "This is a test string";
49+
char accept[] = "tga";
50+
51+
printf("%zu\n", ft_strcspn(haystack, accept));
52+
printf("%zu\n", strcspn(haystack, accept));
53+
}
54+
55+
#endif
56+

0 commit comments

Comments
 (0)