Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- int main()
- {
- beolvas();
- return 0;
- }
- void beolvas(){
- /* declare array */
- int freq[26];
- int ch;
- FILE* txt_file;
- txt_file = fopen("a.txt", "rt");
- fprintf(txt_file, "Azta!");
- /* frequency tábla nullázása */
- for (ch = 0; ch < 26; ch++)
- freq[ch] = 0;
- while (1) {
- ch = fgetc(txt_file);
- if (ch == EOF)break; /* fájl vége, vagy beolvasás probléma. EOF tipikusan -1 */
- /* ASCII kódok a-tól z-ig */
- if ('a' <= ch && ch <= 'z') /* lower case */
- freq[ch-'a']++;
- else if ('A' <= ch && ch <= 'Z') /* upper case */
- freq[ch-'A']++;
- }
- int i;
- for(i=0;i<26;i++){
- printf("%c: %d\n",i+'a' , freq[i]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement