-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strlen.c
More file actions
41 lines (35 loc) · 1.43 KB
/
ft_strlen.c
File metadata and controls
41 lines (35 loc) · 1.43 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlen.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: simarcha <simarcha@student.42barcelona. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/09 13:42:05 by simarcha #+# #+# */
/* Updated: 2024/09/30 12:09:25 by simarcha ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
//strlen's goal is to count the number of letter within a string called s
//if *s is NULL, the strlen from the string.h gives us SEGFAULT
//In my case, I protected *s returning (null), if it doesn't exist
size_t ft_strlen(const char *s)
{
size_t i;
i = 0;
if (!s)
return (0);
while (s[i] != '\0')
i++;
return (i);
}
/*#include <stdio.h>
#include <string.h>
//%zu because strlen is type size_t
int main(void)
{
const char str[14] = "This is a test";
printf("LIB: %zu\n", strlen(str));
printf("ME : %zu\n", ft_strlen(str));
return (0);
}*/