I'm new to programming and we have a project in class asking us to have the user input a sentence then we need to find the character typed most in that sentence. I think I'm on the right track, but I'm getting a segmentation core dump while running the program.
The function I'm using looks like this:
void common(char * string, int x){
cout << "Enter a sentence no longer than " << (SIZE - 1) << " characters long." <<endl;
cin.getline(string,SIZE);
//Use ASCII Values to determine most common character
int a[255] = {0};
int i, mostCommon;
mostCommon = a[0];
i = 0;
for(i=0; &string != 0; i++)
{
if (a[i] > mostCommon)
{
mostCommon = a[i];
x = i;
}
}
cout << "The most common letter in your sentence is " << (char)x << "." <<endl;
}
Any help or insight would be much appreciated.
Thanks,
Jon