Array: Difference between revisions

6 bytes removed ,  15 years ago
m
→‎C: lang tag / - nbsp
(not a task; don't use {{header}})
m (→‎C: lang tag / - nbsp)
Line 37:
We wish to open a text file and compute letter frequency
 
<lang c> FILE *any_text;
/* declare array */
int frequency[26];
/* declare a computed index */
int ch;
 
&nbsp;
any_text = fopen ("a_text_file.txt", "rt");
 
&nbsp;
/* init the freq table: */
for (ch = 0; ch < 26; ch++)
frequency[ch] = 0;
 
&nbsp;
ch = fgetc(any_text);
while (!feof(any_text)) {
Line 55:
frequency[ch-'A'] += 1;
ch = fgetc(any_text);
}</lang>
 
===[[J]]===