Character Frequency Map
C
Hard
3 views
Problem Description
Count the frequency of each character in the string. Create an array of size 256 (his). Then print only the non-zero frequencies.
Official Solution
#include <stdio.h>
int main() {
char str[200];
int freq[256] = {0}; // histogram array
int i;
printf("Enter a string: ");
fgets(str, sizeof(str), stdin);
// Count frequency of each character
for (i = 0; str[i] != '