C Programming Code Examples C > Strings Code Examples C program to find maximum occurring character in a string C program to find maximum occurring character in a string Write a C program to find maximum occurring character in a string using loop. How to find highest frequency character in a string using loop in C programming. Program to find the highest occurring character in a string in C. Input string from user, store it in some variable say str. Declare another array to store frequency of all alphabets, say freq[26]. I have declared size of freq as 26 since there are 26 alphabets in English. Initialize frequencies of all alphabets in freq array to 0. Find frequency of each character present in the string. Maximum occurring character in string is maximum occurring value in the freq array. #include <stdio.h> #define maxsize 100 // Maximum string size #define MAX_CHARS 255 // Maximum characters allowed int main() { char str[maxsize]; int freq[MAX_CHARS]; // Store frequency of each character int j = 0, max; int ascii; printf("Enter any string: "); gets(str); /* Initializes frequency of all characters to 0 */ for(j=0; j<MAX_CHARS; j++) { freq[j] = 0; } /* Finds frequency of each characters */ j=0; while(str[j] != '\0') { ascii = (int)str[j]; freq[ascii] += 1; j++; } /* Finds maximum frequency */ max = 0; for(j=0; j<MAX_CHARS; j++) { if(freq[j] > freq[max]) max = j; } printf("Maximum occurring character is '%c' = %d times.", max, freq[max]); return 0; }