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
Write a program to check palindrome number in c programming?
What are the different types of control structures?
How can I use a preprocessorif expression to ?
any "C" function by default returns an a) int value b) float value c) char value d) a & b
What is const volatile variable in c?
Is main a keyword in c?
What is oops c?
Why is void main used?
p*=(++q)++*--p when p=q=1 while(q<=6)
What is the difference between the = symbol and == symbol?
What library is sizeof in c?
Write a program to replace n bits from the position p of the bit representation of an inputted character x with the one's complement. Method invertBit takes 3 parameters x as input character, p as position and n as the number of positions from p. Replace n bits from pth position in 8 bit character x. Then return the characters by inverting the bits.
What is the use of sizeof?
using only #include
A program is required to print your biographic information including: Names, gender, student Number, Cell Number, line of study and your residential address.