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

What are pointers? What are stacks and queues?

780


What is function in c with example?

837


What is the size of array float a(10)?

897


What is extern keyword in c?

873


How do you construct an increment statement or decrement statement in C?

994


Explain how do you list a file’s date and time?

805


Do pointers store the address of value or the actual value of a variable?

832


What is a node in c?

732


What header files do I need in order to define the standard library functions I use?

755


With the help of using classes, write a program to add two numbers.

842


Here is a good puzzle: how do you write a program which produces its own source code as output?

849


Differentiate between a structure and a union.

1016


What is nested structure?

777


What is the purpose of sprintf?

816


In the DOS enveronment, normal RAM that resides beyond the 1mb mark. a) expanded memory b) swapped memory c) Extended memory d) none

980