Posted by: cp21 September 25, 2015
C++
Login in to Rate this Post:     0       ?        
not sure what am i doing wrong here bro, can you debug and see it for me please


#include
#include
#include
#include

using namespace std;

void initialize(int&, int[]);
void copyText(ifstream&, char&, int[]);
void mostCommon(char,int);
void leastCommon(char,int);

void initialize(int& loc, int list[])
{
loc = 0;
for (int i = 0; i < 26; i++)
list[i] = 0;
}

void count(char ch, int list[])
{
ch = toupper(ch);
int index = static_cast(ch)-static_cast('A');
if (0 <= index && index < 26)
list[index]++;
}

string mostCommon(string input)
{
int max = 0;
int count = 0;
string mostCommonChar;
for (char a = ' '; a <= '~'; a++)

{
count = 0;
for (int i = 0; i;) {
if (input[i] == a)
count++;
}

if (count == max)
{
mostCommonChar += a;
}

if (count > max)
{
max = count;
mostCommonChar = a;

cout << "The letter that occurs most is: " << mostCommon("Hello World") << system("pause");

return mostCommonChar;
}
}


int main()
{
int line;
int letter[26];
char ch;
ifstream infile;

ifstream myfile("c:/letter_count.txt");
if (myfile.is_open())
{
while (getline(myfile, line))
cout << line << '\n';
}
myfile.close();

else cout << "Unable to open file";

}
return 0;
}

Read Full Discussion Thread for this article