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
FILE PROGRAMMING
Do you know what are the properties of union in c?
if the area was hit by a virus and so the decrease in the population because of death was x/3 and the migration from other places increased a population by 2x then annually it had so many ppl. find our the population in the starting.
What is substring in c?
Explain is it better to bitshift a value than to multiply by 2?
Why c is called procedure oriented language?
What is the right type to use for boolean values in c? Is there a standard type? Should I use #defines or enums for the true and false values?
What is the stack in c?
Can include files be nested?
What standard functions are available to manipulate strings?
What is the incorrect operator form following list(== , <> , >= , <=) and what is the reason for the answer?
Why we use void main in c?
the maximum length of a character constant can be a) 1 character b) 8 characters c) 256 chaacters d) 125 characters
Write a program to print fibonacci series without using recursion?
What is wrong in this statement?