-
Notifications
You must be signed in to change notification settings - Fork 0
/
str.c
101 lines (88 loc) · 1.64 KB
/
str.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
** str.c for lemin in /home/franck_r/rendu/lemin
**
** Made by Romain Franck
** Login <franck_r@epitech.net>
**
** Started on Tue Mar 25 12:28:20 2014 Romain Franck
** Last update Fri May 2 14:48:10 2014 root
*/
#include <stdlib.h>
int my_strlen_no_troll(const char *s_ptr)
{
size_t i;
i ^= i;
if (s_ptr == NULL)
return (0);
while (s_ptr[i])
i++;
return (i);
}
char *my_strdup_no_troll(char *src)
{
char *str;
int i;
i = 0;
if (!src ||
(str = malloc(sizeof(char) * (my_strlen_no_troll(src) + 1))) == NULL)
return (NULL);
while (src[i])
{
str[i] = src[i];
i++;
}
str[i] = 0;
return (str);
}
int my_strcmp_no_troll(char *s1, char *s2)
{
char *s1_ptr;
char *s2_ptr;
s1_ptr = s1;
s2_ptr = s2;
while (!(*s1_ptr - *s2_ptr) && *s1_ptr && *s2_ptr)
{
s1_ptr++;
s2_ptr++;
}
return (*s1_ptr - *s2_ptr);
}
int my_strncmp(const char *s1, const char *s2, int n)
{
int i;
int value;
if (!n)
return (0);
i ^= i;
value ^= value;
while (i < n && !value && s1[i] && s2[i])
{
value = s1[i] ^ s2[i];
i++;
}
return (s1[i] - s2[i]);
}
int my_strcmp(char *a, char *b)
{
return (*a == *b ? *a ? my_strcmp(a + 1, b + 1) : 1 : 0);
}
int my_strlen(char *s, int i)
{
return (*(s + i) && *(s + i) != '-' && *(s + i) != 10 && *(s + i) != 32
? 1 + my_strlen(s + 1, i) : 1);
}
char *my_strdup(char *s, int i)
{
char *r;
int a;
a = 0;
if ((r = malloc(my_strlen(s, i))) == NULL)
return (NULL);
while (s[i + a] && s[a + i] != '-' && s[i + a] != 10 && s[i + a] != 32)
{
r[a] = s[i + a];
a++;
}
r[a] = 0;
return (r);
}