Skip to content

Commit 47e8803

Browse files
committed
added: 2-strlen.c
1 parent f21e7da commit 47e8803

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

0x05-pointers_arrays_strings/2-main.c

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include "main.h"
2+
#include <stdio.h>
3+
4+
/**
5+
* main - check the code
6+
*
7+
* Return: Always 0.
8+
*/
9+
int main(void)
10+
{
11+
char *str;
12+
int len;
13+
14+
str = "My first strlen!";
15+
len = _strlen(str);
16+
printf("%d\n", len);
17+
return (0);
18+
}
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include "main.h"
2+
3+
/**
4+
* _strlen - return the length of a string.
5+
*
6+
* @s: string.
7+
*
8+
* Return: length of the string.
9+
*/
10+
int _strlen(char *s)
11+
{
12+
char *ptr;
13+
int size = 0;
14+
15+
ptr = s;
16+
while (*ptr != '\0')
17+
{
18+
size = sizeof(*ptr) + size;
19+
ptr = ptr + 1;
20+
}
21+
return (size);
22+
}

0x05-pointers_arrays_strings/main.h

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
int _putchar(char);
22
void reset_to_98(int *);
33
void swap_int(int *, int *);
4+
int _strlen(char *);

0 commit comments

Comments
 (0)