Frequency of each character in the string

#include<stdio.h>
void main()
{
char s[100];
int f[256]={0},i,j;
fgets(s,100,stdin); //gets(s);
for(i=0;s[i]!='\0';i++)
{
f[s[i]]++;
}
for(i=0;i<256;i++)
{
if(f[i]>0)
printf("%c occurs %d times\n",i,f[i]);
}
}
Input:
helLo how@are_raju*@#
Output
 occurs 1 times
  occurs 1 times
# occurs 1 times
* occurs 1 times
@ occurs 2 times
L occurs 1 times
_ occurs 1 times
a occurs 2 times
e occurs 2 times
h occurs 2 times
j occurs 1 times
l occurs 1 times
o occurs 2 times
r occurs 2 times
u occurs 1 times
w occurs 1 times

No comments:

Post a Comment