Advertisement
Guest User

huffman beolvas

a guest
Nov 30th, 2015
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.79 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int main()
  5. {
  6.     beolvas();
  7.     return 0;
  8. }
  9.  
  10. void beolvas(){
  11.     /* declare array */
  12.     int freq[26];
  13.     int ch;
  14.     FILE* txt_file;
  15.     txt_file = fopen("a.txt", "rt");
  16.     fprintf(txt_file, "Azta!");
  17.     /* frequency tábla nullázása */
  18.     for (ch = 0; ch < 26; ch++)
  19.         freq[ch] = 0;
  20.  
  21.     while (1) {
  22.         ch = fgetc(txt_file);
  23.         if (ch == EOF)break; /* fájl vége, vagy beolvasás probléma. EOF tipikusan -1 */
  24.  
  25.         /* ASCII kódok a-tól z-ig */
  26.         if ('a' <= ch && ch <= 'z')      /* lower case */
  27.             freq[ch-'a']++;
  28.         else if ('A' <= ch && ch <= 'Z') /* upper case */
  29.             freq[ch-'A']++;
  30.     }
  31.     int i;
  32.     for(i=0;i<26;i++){
  33.         printf("%c: %d\n",i+'a' , freq[i]);
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement