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 are logical errors and how does it differ from syntax errors?
What does. int *x[](); means ?
What is a struct c#?
Mention four important string handling functions in c languages .
Why is struct padding needed?
Which header file is used for clrscr?
Explain argument and its types.
Write a C++ program to generate 10 integer numbers between - 1000 and 1000, then store the summation of the odd positive numbers in variable call it sum_pos, then find the maximum digit in this variable regardless of its digits length.
what is the significance of static storage class specifier?
Explain what standard functions are available to manipulate strings?
What are the different types of control structures in programming?
What is || operator and how does it function in a program?
What is the difference between local variable and global variable in c?
What is #include in c?
How do you determine the length of a string value that was stored in a variable?