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
What are pointers? What are stacks and queues?
What is function in c with example?
What is the size of array float a(10)?
What is extern keyword in c?
How do you construct an increment statement or decrement statement in C?
Explain how do you list a file’s date and time?
Do pointers store the address of value or the actual value of a variable?
What is a node in c?
What header files do I need in order to define the standard library functions I use?
With the help of using classes, write a program to add two numbers.
Here is a good puzzle: how do you write a program which produces its own source code as output?
Differentiate between a structure and a union.
What is nested structure?
What is the purpose of sprintf?
In the DOS enveronment, normal RAM that resides beyond the 1mb mark. a) expanded memory b) swapped memory c) Extended memory d) none