Program in C Language to find a frequenct of character in string



Click here to open this program in Turbo C++

/*******************************************************
 Statement - Find a frequenct of character in string
 Programmer - Vineet Choudhary
 Written For - http://developerinsider.in
 *******************************************************/

#include <stdio.h>
#include <string.h>
#include <conio.h>

void find_frequency(char [], int []);

void main()  
{
    char string[100];
    int c, count[26] = {0};
    clrscr();

    printf("Input a string\n");
    gets(string);

    find_frequency(string, count);

    printf("Character Count\n");

    for (c = 0 ; c < 26 ; c++)
    {
        printf("%c \t  %d\n", c + 'a', count[c]);
    }

    getch();
}

void find_frequency(char s[], int count[]) {  
    int c = 0;

    while (s[c] != '\0') {
        if (s[c] >= 'a' && s[c] <= 'z' )
            count[s[c]-'a']++;
        c++;
    }
}