Hi..
Could anyone help me to find out why this program cannot count the frequency of each alphabet? There is a output for calculating the total lines and length but not the frequency.Appreciate any help. Thanks!
int main()
{
const int MAXLENGTH=10;
const int MAXCHARS=10000;
static double i[26];
char filename[MAXLENGTH]="ex.txt";
char descrip[MAXCHARS];
string lineBuffer;
int length=0;
int lineCount = 1;
char str2[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'};
int ch,count,z,q;
ifstream infile;
infile.open(filename, ios::in);
if(infile.fail())
{
cout<<"The file was not successfully opened"<<endl;
getch();
exit(1);
}
while(!infile.eof())
{
getline(infile, lineBuffer);
int count = 1;
count = lineCount;
cout << "\nThe line now are : " << count << endl;
lineCount ++;
length = lineBuffer.length();
cout << "The length of line are : " << length << endl;
for(z = 0; z < count; z++)
{
for(q=0; q < 27 ; q++)
{
if( descrip[z]== str2[q])
i[q]++;
}
}
for(q=0; q < 26; q++)
{
double g;
g=i[q]/count;
cout<<g<<endl;
}
}
infile.close();
cout<<endl;
getch();
return 0;
}