Hey So I have made progress but I'm not quite there. I give a function a word. This word is converted to upper case. The word is then indexed through. Each position(call it i) is subtracted from 65 then incremented. So 'A' corresponds to 0 when I output. The letters. So I gave the function the word "haha" so for output I get 7 0 7 0. So 7 is H 0 is A. But I don't really want this. I want it to be an array of 26 initialized to 0. So instead of 7 0 7 0 it will just increment position 0 two times. It will increment position 7 two times. So lets pretend we are starring at the array
| 2 | | | | | | | 2 |.....to 26.
Above the first 2 corresponds to A the seventh position corresponds to H.
So really it is just an array that tally's the letters. So I can display the frequency of each occurrence of each letter in the alphabet.
I just tried your idea I didn't get anything different in the output. I"m so lost it is this one step that's the problem. How do I get the frequency into the array to increment you know like is there is "B" and "B" the frequency of position 1 will be 2.
Thanks for input though dude.
No that is exactly what I want for the array. But you have a few things I don't understand.
for instance memset(freqcount, 0, 26*sizeof(int));
what does this mean? Also why does the output have haha? Just curious I appreciate you helping me. I have not learned this memset thing. Is there a way to do it with out it?
I used memset to write zeroes to all of the values in the array, but you can just use a for loop to accomplish the same thing. Once you do so, that should fix your problem.
Dude I'm telling you my output it not the same it is just 26 numbers like 23312
Why would it not work the same? I don't understand. Yeah that's so funny you mention the int main my teacher uses void main and everyone on here hates it! I don't care about the 0's right now I just want the frequency of each letter to be right. I'm mean it is exactly the same why is it not working ahhh so close so frustrating. Dude thanks
When the os allocates space for 'freqcount,' it inherits whatever garbage is already present in memory. This is a problem now because we are incrementing those garbage values, instead of "setting" them like you were doing before (which is why it wasn't a problem).
Example of what 'freqcount' could look like when created:
[1251, 1321579, 392, 0, 23, 1230, 2, 19384, ...]
What it would look like after calling 'fillFrequency' (without setting all those junk values to zero first)
[1253, 1321579, 392, 0, 23, 1230, 2, 19386, ...]
What it would look like if you set all of the values to zero before calling 'fillFrequency':
[2, 0, 0, 0, 0, 0, 0, 2, ...]
The program is behaving how it should, but the results are skewed because you don't initialize 'freqcount'. In C++ it's important to initialize variables to some value, or else problems like the above can show up.