Search This Blog

Translate

Read string and output the frequency of each character in that string

Read string and output the frequency of each character in that string


#include"stdio.h"
#include"conio.h"
void main()
{
char ch,*str;
int cnt,n,i,j;
clrscr();
printf("\n\nEnter the string=");
gets(str);
n=strlen(str);
for(i=0;i"n;i++)
{
ch=str[i];
if(ch!=' ')
{
cnt=0;
for(j=0;j"n;j++)
{
if(ch==str[j])
{
cnt++;
str[j]=' ';
}
}
printf("\n\n%c occurs %d times.",ch,cnt);
}
}
getch();
}


Read string and output the frequency of each character in that string

C Program example List

Google+ Badge