-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuildAlphabet.c
More file actions
44 lines (37 loc) · 831 Bytes
/
buildAlphabet.c
File metadata and controls
44 lines (37 loc) · 831 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
41
42
43
44
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define CHARACTER_COUNT 128
void load_frequency(char *input_filename, int character_frequency[])
{
FILE *fp = fopen(input_filename, "rb");
if (fp == NULL)
{
printf("Error: Filename could not be opened\n");
exit(2);
}
char c = fgetc(fp);
while (c != EOF)
{
character_frequency[c]++;
c = fgetc(fp);
}
fclose(fp);
}
int main(int argc, char *argv[])
{
int character_frequency[CHARACTER_COUNT];
for (int i = 0; i < CHARACTER_COUNT; i++)
{
character_frequency[i] = 0;
}
for (int i = 1; i < argc; i++)
{
load_frequency(argv[i], character_frequency);
}
for (int j = 0; j < 128; j++)
{
printf("%d,", character_frequency[j]);
}
return 0;
}