C program to find frequency of each character in a text
file?
Answer Posted / mahfooz alam
#include <iostream>
#include<fstream>
using namespace std;
int main()
{
int arr[26]={0},i;
ifstream fin;
ofstream fout;
fout.open("input.txt",ios::app);
fin.open("input.txt",ios::out);
char c;
fin>>c;
while(!fin.eof())
{
if(isalpha(c))
{
tolower(c);
switch(c)
{
case 'a':
arr[0]++;
break;
case 'b':
arr[1]++;break;
case 'c':
arr[2]++;break;
case 'd':
arr[3]++;break;
case 'e':
arr[4]++;break;
case 'f':
arr[5]++;break;
case 'g':
arr[6]++;break;
case 'h':
arr[7]++;break;
case 'i':
arr[8]++;break;
case 'j':
arr[9]++;break;
case 'k':
arr[10]++;break;
case 'l':
arr[11]++;break;
case 'm':
arr[12]++;break;
case 'n':
arr[13]++;break;
case 'o':
arr[14]++;break;
case 'p':
arr[15]++;break;
case 'q':
arr[16]++;break;
case 'r':
arr[17]++;break;
case 's':
arr[18]++;break;
case 't':
arr[19]++;break;
case 'u':
arr[20]++;break;
case 'v':
arr[21]++;break;
case 'w':
arr[22]++;break;
case 'x':
arr[23]++;break;
case 'y':
arr[24]++;break;
case 'z':
arr[25]++;break;
}
}
fin>>c;
}//endl of while.*/
for(i=0;i<26;i++)
fout<<"no of letter "<<static_cast<char>(i+65)<<" is
"<<arr[i]<<endl;
fin.close();
return 0;
}
Is This Answer Correct ? | 4 Yes | 29 No |
Post New Answer View All Answers
What is volatile, register definition in C
difference between native and cross compilers
What do you mean by a sequential access file?
Explain the process of converting a Tree into a Binary Tree.
What is omp_num_threads?
What is the size of enum in c?
what is the different bitween abap and abap-hr?
Is c a great language, or what?
How can I write a function analogous to scanf?
count = 0; for (i = 1;i < = 10; i++);count = count + i; Value of count after execution of the above statements will be a) 0 b) 11 c) 55 d) array
What is queue in c?
Can stdout be forced to print somewhere other than the screen?
What is c system32 taskhostw exe?
Write a program that accept anumber in words
How can you call a function, given its name as a string?