C Program to Find the Frequency of Characters in a String

This program asks user to enter a string and a character and this program checks how many times that character is repeated in the string entered by user.

Source Code to Find the Frequency of Characters


#include <stdio.h>
int main(){
   char c[1000],ch;
   int i,count=0;
   printf("Enter a string: ");
   gets(c);
   printf("Enter a characeter to find frequency: ");
   scanf("%c",&ch);
   for(i=0;c[i]!='\0';++i)
   {
       if(ch==c[i])
           ++count;
   }
   printf("Frequency of %c = %d", ch, count);
   return 0;
}

Output

Enter a string: This website is awesome.
Enter a frequency to find frequency: e
Frequency of e = 4