Hi,
I have been working on this small console applications for 2-3 days now but I cannot find the problem.
The Task is that I have to read a file which has sentences in english and I just have to get the frequency for each character and print it out on the screen like this:
Character Frequency
a 1
etc.
Now the problem with my code is that it is counting the first character properly but for all other characters I get a zero Value, Here is my code:
It is a function..
void Character_Freq()
{
ifstream In_File;
char c;
int i,count;
In_File.open("infile.txt");
cout<<"Characters\tFrequency"<<endl;
if(In_File.is_open())
{
for(i=97;i<=122;i++)
{
count = 0;
c = (char)i;
while(!In_File.eof())
{
if((char)In_File.get()== c)
{
count++;
}
else
{
//Don't Count
}
}
In_File.close();
cout<<(char)i<<"\t\t"<<count<<endl;
In_File.open("infile.txt");
}
}
else
{
cout<<"\nFile was unreadable";
}
In_File.close();
}
Now I don't know what I am missing, it would be really helpful if someone can spot the mistake thanks.
And another thing is that I am not allowed to use any more variables in this program.
So in other words I can only use One Char, two Ints and One file streamer
Thanks in Advance