I have to write a program that accepts a pointer to a c-string as its argument. The function should return the charater that appears most frequently in the string along with the number of times it appears. for example, if i input "hello dolly" the output would be: "l sppears 4 times"
I am just working on the basics and it prints out the last number, but counts the stuff right. should i use string compare or something to compare the strings correctly. heres the code
#include <iostream>
#include <cctype>
#include <cstring>
using namespace std;
int main()
{
const int SIZE=40;
const int LETTERS=26;
char strings[SIZE];
int numberOfTimes[LETTERS];
int length;
int max=0;
cout << "enter the string" << endl;
cin.getline(strings,SIZE);
strlwr(strings);
length = strlen(strings);
char alphabet[] = {'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'};
for(int i=0; i<LETTERS; i++)
{
numberOfTimes[i]=0;
for(int j=0; j<length; j++)
{
if(alphabet[i]==strings[j])
{
numberOfTimes[i]+=1;
}
}
if(numberOfTimes[i] > numberOfTimes[i-1])
{
max=i;
}
}
cout << alphabet[max] << " appears " << numberOfTimes[max] << endl;
return 0;
}