-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrstr_capitalizer.c
89 lines (80 loc) · 1.77 KB
/
rstr_capitalizer.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* rstr_capitalizer.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hdecaux <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/10 08:43:16 by hdecaux #+# #+# */
/* Updated: 2015/11/10 09:35:09 by hdecaux ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
void ft_putchar(char c)
{
write(1, &c, 1);
}
void ft_putstr(char *str)
{
int i;
i = 0;
while (str[i])
{
ft_putchar(str[i]);
i++;
}
}
int ft_ispace(char c)
{
if (c == ' ' || c == '\t')
return (1);
else
return (0);
}
void rstr_capitalizer(char *str)
{
int i;
char *t;
char *s;
i = 0;
s = str;
t = str;
while (s[i])
{
if (s[i] >= 65 && s[i] <= 90 && ft_ispace(s[i + 1]) == 0)
{
t[i] = s[i] + 32;
i++;
}
else if (ft_ispace(s[i]) == 1 && s[i - 1] >= 97 && s[i - 1] <= 122)
{
t[i - 1] = s[i - 1] - 32;
t[i] = s[i];
i++;
}
else
{
t[i] = s[i];
i++;
}
}
if (t[i -1] >= 97 && t[i - 1] <= 122)
{
t[i - 1] = t[i - 1] - 32;
}
ft_putstr(t);
ft_putchar('\n');
}
int main(int argc, char **argv)
{
int i;
i = 1;
if (argc == 1)
ft_putchar('\n');
while (argc != 1)
{
rstr_capitalizer(argv[i]);
i++;
}
return (0);
}