Finding and printing the most frequent letter in an array?

...
Last edited on
Lines 56 and 57 are backwards.
I reversed them, but now every time I run the program, it crashes after the function is called stating "MostFrequentChar is being used without being initialized". Isn't the statement in the loop an initialization?
The program runs fine for me hmm.

Edit: Just try doing this char MostFrequentChar = 'a'; see if that works instead.
Last edited on
Weird, I'm not getting an error after reversing them... It works correctly for me except for the fact that you don't change the characters to all uppercase or all lowercase first.

And no, the statement in the loop is called an assignment. An initialization is when you assign a value at the time of the variable's declaration.

EDIT: Was just about to suggest the same as TarikNeaj. Maybe your compiler is just really picky. I mean, I suppose you could be using an unitialized MostFrequentChar if you never go through the assignment in the loop due to every value in Frequencies[] begin equal or less than 0. But you would have to input something like:

THIS SENTENCE WILL RESULT IN NO LETTERS BEING COUNTED BECAUSE THERE ARE NO LOWER CASE LETTERS, LEADING TO AN UNINITIALIZED MOSTFREQUENTCHAR VARIABLE AND UNDEFINED BEHAVIOR WHEN TRYING TO OUTPUT IT.
Last edited on
Haha well I did it that way and now it is working! I guess it was just my compiler. Thanks for the help!
Topic archived. No new replies allowed.