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
How can you call a function, given its name as a string?
Do you know the difference between malloc() and calloc() function?
How can I avoid the abort, retry, fail messages?
List some of the static data structures in C?
What is the difference between typedef and #define?
why use "return" statement a) on executing the return statement it immediately transfers the control back to the calling program b) it returns the value present in the parentheses return, to the calling program c) a & b d) none of the above
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 wrong in this statement? scanf(ā%dā,whatnumber);
Can include files be nested? How many levels deep can include files be nested?
What should malloc(0) do?
What is wrong with this program statement?
write a program using linked list in which each node consists of following information. Name[30] Branch Rollno Telephone no i) Write the program to add information of students in linked list
What is masking?
Why we use int main and void main?
general for is %wd,f-d; in this system "w" means a) 'w' represent total width of digits b) 'w' represent width which includes the digits before,after decimal place and the decimal point c) 'w' represent width which includes the digits before only d) 'w' represent width after decimal place only