Write a program that will prompt the user for a string Read
Write a program that will prompt the user for a string. Read the string using gets(). Convert the string to all capitals using your my_strupper function from the earlier problem. Next, write a loop to cycle thru each character of the string, and count the occurance of each letter. Store these values in int freqs[26];//hmmm, what does this do?? freqs[str[i] - \'A\']++;//hmmm, and this?? printf(\"%c %d\ \", i + \'A\', freqs[i]); Sample Output: Please enter a string: Foobar A 1 B 1 F 1 O 2 R 1 Press any key to continue...
Solution
Answer:-
#include <stdio.h>
#include <string.h>
void find_frequency(char [], int []);
int main()
{
char string[100];
int c, count[26] = {0};
printf(\"Input a string\ \");
gets(string);
find_frequency(string, count);
printf(\"Character Count\ \");
for (c = 0 ; c < 26 ; c++)
printf(\"%c \\t %d\ \", c + \'a\', count[c]);
return 0;
}
void find_frequency(char s[], int count[]) {
int c = 0;
while (s[c] != \'\\0\') {
if (s[c] >= \'a\' && s[c] <= \'z\' )
count[s[c]-\'a\']++;
c++;
}
}
