Hello guys,
I wanna write a program that count for me the number of each letter I have in a text file then I want to cout the words and count the number of repetition of each word.
I was able to do it except for counting the repetition
And here is my code:
#include <iostream>
#include <fstream>
#include <iomanip>
#include <stdlib>
#include <cstring>
#include <stdio>
#include <conio>
int main()
{
char ch; int num[100]={0}; string read; string k[10];
string q[10], news; int index=0,indecies=0;
const int arraysize=27;
char a[arraysize]={'q','w','e','r','t','y','u','i','o','p','a','s','d','f',
'g','h','j','k','l','z','x','c','v','b','n','m',' '};
int freq[arraysize]={0};
ifstream fin("mah.txt");
if (!fin.good())
{
cout << "Cannot find your location" << endl;
}
while ((ch = fin.get()) != EOF) {
for(int j=0;j<=arraysize;j++)
{
if (ch==a[j])
freq[j]=freq[j]+1;
}
if (ch==' ')
{
index++;
for(int j=0;j<=index-2;j++)
if(q[j]==q[index-1])
num[j]++;
for(int i=0;i<=index;i++)
if(q[i]!=' ')
k[i]=q[i];
}
else
q[index].append(ch);
}
cout << endl;
fin.close();
for(int j=0;j<arraysize;j++)
cout<<setw(2)<<(j+1)<<" the freq of "<<a[j]<<" is "<<freq[j]<<".\n";
for(int i=0;i<=index;i++)
cout<<k[i]<<endl;
getch ();
return 0;
}
Waiting for you help