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
Explain output of printf("Hello World"-'A'+'B'); ?
What are reserved words with a programming language?
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
What is advantage of pointer in c?
Explain logical errors? Compare with syntax errors.
How many data structures are there in c?
Suggesting that there can be 62 seconds in a minute?
Tell me about low level programming languages.
Why is event driven programming or procedural programming, better within specific scenario?
If the size of int data type is two bytes, what is the range of signed int data type?
What does main () mean in c?
What is meant by high-order and low-order bytes?
A character flag or control mechanism that delineates one data item from another a) variable b) constant c) delimiter d) call by reference
What is the use of header files?
is it possible to create your own header files?