Hi,
I have a text file with characters. I must able to read the length of characters in the file by every line and count the frequency of each characters for each line. I have tried on writing this program but this does not work. Can anyone help me on this? Thank you in advance.
int main()
{
const int MAXLENGTH=10;
const int MAXCHARS=1000;
static double i[26];
char filename[MAXLENGTH]="ex.txt";
char descrip[MAXCHARS];
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((ch=infile.get())!=EOF)
{
count = strlen(descrip);
cout<<"\nThe length of the string is: "<<count<<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;
}