|
|
|
|
int cnt[26];
goes after line 12 in your program. memset goes before line 15. cnt[c-'A']++;
goes after line 18. c-'A'
is an expression that converts c to an array index. If c contains 'A', then c-'A' is zero. If c contains 'B', then c-'A' is 1, etc.
|
|
++(freqcount[str1[i] - 'A']);
2 | | | |.....
|
|
|
|
++(freqcount[str1[i] - 'A']);
Is now ++(freqcount[66-65]);
Remember 'A' is 65. So it really is just saying this ++(freqcount[1]);
. 3 | 6 | 1 | 9 | .....=>
So position 0 represents 'A' and 1 represents 'B' and so forth. ++(freqcount[str1[i] - 'A']);
IT will know to add something to number one because of the ++. 'A' is just a value of '65'. So if you got B it would be 65-64 which is 1. So it will go to position 1 then lastly it ++ position one. This does it for every letter you get. Please go to ascii table look at the values of the uppercase letters. Remember that your array size is 26. Take any of the values for uppercase and walk through the code.
|
|
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. |
A occurs 29 times B occurs 3 times C occurs 16 times D occurs 19 times E occurs 38 times F occurs 3 times G occurs 3 times H occurs 1 times I occurs 43 times J occurs 0 times K occurs 0 times L occurs 22 times M occurs 17 times N occurs 24 times O occurs 29 times P occurs 11 times Q occurs 5 times R occurs 22 times S occurs 18 times T occurs 32 times U occurs 29 times V occurs 3 times W occurs 0 times X occurs 3 times Y occurs 0 times Z occurs 0 times |
isalpha()
. Similarly, there are both lower and upper case letters, hence toupper()
is used.
|
|
int index
I have to adjust it, effectively subtracting 65 from the code of the each particular character.No code actually works when I run it |
I am continuing to pursue an answer, don't get me wrong, but at this point it looks like I'm not going to find it in a forum |
I just don't get how you get that information from the A to the frequency array.
freqcount[12]
This is at position 12 Right ? GO TO THE ASCII TABLE A HAS A VALUE OF 65 (UPPERCASE). 66(B) - 65(A) is 1freqcount[1]
This one is position 1 just like 12 a few sentences ago. Now the ++ on the outside of ++(freqcount[1])
litterally saying INCREMENT POSITION 1 BY ONE COUNT