C program to find frequency of each character in a text
file?

Answer Posted / m. umar naeem

#include <iostream>
#include <fstream>
using namespace std;

int main()
{
ifstream ifile;
ifile.open("input.txt");
if (!ifile)
{
cout << "file not found!
";
return 1;
}
char a[26] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char c; int d[26] = { 0 };
while (ifile)
{
ifile.get(c);
if (c >= 'A' && c <= 'Z')
d[c - 65]++;
else if (c >= 'a' && c <= 'z')
d[c - 97]++;
}
for (int i = 0; i < 26; i++)
{
cout << a[i] << "=" << d[i] << endl;
}
ifile.close();
return 0;
}

Is This Answer Correct ?    0 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain output of printf("Hello World"-'A'+'B'); ?

1193


What are reserved words with a programming language?

855


in case any function return float value we must declare a) the function must be declared as 'float' in main() as well b) the function automatically returned float values c) function before declared 'float' keyword d) all the above

822


What is advantage of pointer in c?

938


Explain logical errors? Compare with syntax errors.

844


How many data structures are there in c?

850


Suggesting that there can be 62 seconds in a minute?

817


Tell me about low level programming languages.

893


Why is event driven programming or procedural programming, better within specific scenario?

2182


If the size of int data type is two bytes, what is the range of signed int data type?

808


What does main () mean in c?

872


What is meant by high-order and low-order bytes?

856


A character flag or control mechanism that delineates one data item from another a) variable b) constant c) delimiter d) call by reference

866


What is the use of header files?

843


is it possible to create your own header files?

855