C program to check the number of occurences of each characters in a string

Output:

welcome                                                                                                                                        
c->1                                                                                                                                           
e->2                                                                                                                                           
l->1                                                                                                                                           
m->1                                                                                                                                           
o->1                                                                                                                                           
w->1

thetestofmylife                                                                                                                                
e->3                                                                                                                                           
f->2                                                                                                                                           
h->1                                                                                                                                           
i->1                                                                                                                                           
l->1                                                                                                                                           
m->1                                                                                                                                           
o->1       

Program:

#include <stdio.h>

int main()
{
    char str[100];
    scanf("%s",str);
    int i,a[26]={0};
    int c=0;
    while(str[c]!='\0')
    {
        a[str[c]-'a']++;
        c++;
    }
    for(i=0;i<26;i++)
    {
        if(a[i]>=1)
        {
            char temp=i+97;
            printf("%c->%d \n",temp,a[i]);
        }
    }
    return 0;
}

Comments

Popular posts from this blog

C program to print the following Pattern

c++ program to print string along the diagonals of the matrix.

Kollywood Game