-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_tolower.c
66 lines (58 loc) · 1.85 KB
/
ft_tolower.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_tolower.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yuske <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/24 15:44:31 by yfurutat #+# #+# */
/* Updated: 2022/11/20 01:03:45 by yuske ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
// int main(void)
// {
// printf("%c\n", ft_tolower('Q'));
// return (0);
// }
//1. magic nbr -> better be avoided
// int ft_tolower(int i)
// {
// if (i >= 65 && i <= 90)
// i = i + 32;
// return (i);
// }
//2. character literal -> better than 1, but not best
// int ft_tolower(int i)
// {
// if (i >= 'A' && i <= 'Z')
// i += ' ';
// return (i);
// }
//3. is this easier to understand even for the beginners?
// better use fewer funcs?
// static int ft_isupper(int c)
// {
// return (c >= 'A' && c <= 'Z');
// }
// int ft_tolower(int i)
// {
// if (ft_isupper(i))
// i += ('a' - 'A');
// return (i);
// }
//4. express with the dif -> should look clearer than the previous
int ft_tolower(int i)
{
if (i >= 'A' && i <= 'Z')
i -= ('A' - 'a');
return (i);
}
//5. 4 might be the easiest to intuitively understand
//is there any difference in the process speed?
// int ft_tolower(int i)
// {
// if (i >= 'A' && i <= 'Z')
// i += ('a' - 'A');
// return (i);
// }