forked from CPRO-Session1/Assignment4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharrayfreq.c
More file actions
40 lines (34 loc) · 709 Bytes
/
arrayfreq.c
File metadata and controls
40 lines (34 loc) · 709 Bytes
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
/* Christopher Liu */
#include <stdio.h>
#include <string.h>
int main()
{
char string[100] = {};
char reference[53] = {"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"};
int counter[53] = {};
for (int i = 0; i < (int) strlen(string); i++)
{
counter[i] = 0;
}
printf("Enter string: ");
fgets(string, sizeof(string), stdin);
string[strlen(string)-1] = '\0';
for (int i = 0; i < (int) strlen(string); i++)
{
for (int j = 0; j < (int) strlen(reference); j++)
{
if (string[i] == reference[j])
{
counter[j] += 1;
}
}
}
for (int i = 0; i < (int) sizeof(counter)/4; i++)
{
if (counter[i] != 0)
{
printf("%c: %d\n", reference[i], counter[i]);
}
}
return 0;
}