C Program to find frequency of character in string


In this program, You will learn how to find frequency of character in string in c.


String is: Xiith

t frequency is: 1 times in string


Example: How to find frequency of character in string in c

Run it Now
#include<stdio.h>
#include<string.h>

int main() {

   char a[100], b;
   int i = 0, c = 0;

   printf("Enter a String :");
   fgets(a, 100, stdin);

   printf("\nEnter a Character :");
   scanf("%c", &b);

   i = strlen(a);

   for (int j = 0; j < i; j++) {
       if (a[j] == b){
         c++;
       }
   }
   printf("\nTotal Frequency is :%d", c);

   return 0;
}

Output:

Enter a String :John h#$!@32
Enter a Character :h
Total Frequency is :2