Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
19
Task/Letter-frequency/C/letter-frequency.c
Normal file
19
Task/Letter-frequency/C/letter-frequency.c
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
/* declare array */
|
||||
int frequency[26];
|
||||
int ch;
|
||||
FILE* txt_file = fopen ("a_text_file.txt", "rt");
|
||||
|
||||
/* init the freq table: */
|
||||
for (ch = 0; ch < 26; ch++)
|
||||
frequency[ch] = 0;
|
||||
|
||||
while (1) {
|
||||
ch = fgetc(txt_file);
|
||||
if (ch == EOF) break; /* end of file or read error. EOF is typically -1 */
|
||||
|
||||
/* assuming ASCII; "letters" means "a to z" */
|
||||
if ('a' <= ch && ch <= 'z') /* lower case */
|
||||
frequency[ch-'a']++;
|
||||
else if ('A' <= ch && ch <= 'Z') /* upper case */
|
||||
frequency[ch-'A']++;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue