In C language Write a program that will prompt the user for

In C language!!!!

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]; Hint: In the loop, convert each character in the string into a zero-based index by subtracting \'A\', and use this as an index into freqs. Lastly, use freqs and a loop to output a table of these letters and their frequencies, ommiting those with a frequency of zero. Do not use any string processing library functions. Hint:

// 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

#include #include int main() { char s[]; int i, l; int freq[26]; /* Reads a string from user */ printf(\"Enter a string: \"); gets(s); l = strlen(s); /* Initializes frequency of each character to 0 */ for(i=0; i<26; i++) { freq[i] = 0; } /* Finds total number of occurrences of each character */ for(i=0; i=\'a\' && s[i]<=\'z\') { freq[s[i] - 97]++; } else if(s[i]>=\'A\' && s[i]<=\'Z\') { freq[s[i] - 65]++; } } printf(\"\ Frequency: \ \"); for(i=0; i<26; i++) { printf(\"%c = %d\ \", (i+97), freq[i]); } return 0; }
In C language!!!! 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_struppe

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site