Find a frequenct of character in string - C Language Programming

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.co
 *******************************************************/

#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++;
    }
}
You've successfully subscribed to Developer Insider
Great! Next, complete checkout for full access to Developer Insider
Welcome back! You've successfully signed in
Success! Your account is fully activated, you now have access to all content.