-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path1_2_count_alpha(no_stack).c
56 lines (50 loc) · 1.5 KB
/
1_2_count_alpha(no_stack).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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* count_alpha.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qpeng <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/02/04 20:20:31 by qpeng #+# #+# */
/* Updated: 2019/02/04 20:43:45 by qpeng ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdio.h>
#define cvt(c) (int)_tolower(av[1][c])
int _isLetter(int c)
{
return (c >= 'a' && c <= 'z')
|| (c >= 'A' && c <= 'Z');
}
char _tolower(int c)
{
if (c >= 'A' && c <= 'Z')
return (c + 32);
return (c);
}
int main(int ac, char **av)
{
if (ac != 2)
{
printf("\n");
return (0);
}
char hm[127];
for (int i = 0; av[1][i]; i++)
hm[(int)_tolower(av[1][i])]++;
int printed = 0;
for (int i = 0; av[1][i]; i++)
{
if (_isLetter(av[1][i]) && hm[cvt(i)])
{
if (!printed)
printed = 1;
else
printf(", ");
printf("%d%c", hm[cvt(i)], cvt(i));
hm[cvt(i)] = 0;
}
}
printf("\n");
return (0);
}