Pages

Subscribe:

To Count Number Of Occurrences Of A Characters/Letters Sequence In A String

Here C program to count the number of  occurrences of a  characters/letters sequence  in a string.This c program use ASCII value of small letter for looping and checking .

Example :

  • String : hello 
  • "h" found 1 time
  • "e" found 1 time 
  • " l" found 2 time
  • "o" found 1 time
Program :




#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char ch;
do{
    char a[20],f=0;
    int i,n,ascii;
    clrscr();
printf("enter a string:");
     gets(a);
     strlwr(a); // Sting convert in small letter 

        for(ascii=97;ascii<=122;ascii++)// a=97 and z=122 ascii value for looping 
        {
        n=0;
        f=0;
        for(i=0;a[i]!=NULL;i++)
        {
        
            if(ascii==a[i])// Ascii value for checking
            {    
                n++; // If Checking sucessfull ..increment +1
                f=1; 
            }
        }
        if(f==1) // Checking f value is similar or not 
            printf("\t\t%c value found %d times ",ascii,n); 
        }
        printf("\n\t continue (y/n):");
        ch=getch();
}while(ch=='y'||ch=='Y');

}


Output :





If you have any Further Information and Quires about this Article don't hesitate to comment in comment box below.
                                                           AND

 If you like this article , like our Facebook like page and click  +1 to support 123techguide
comments powered by Disqus
 

Listed In

Bloggers - Meet Millions of Bloggers http://Link-exchange.comxa.com
Blog Search: The Source for Blogs Internet Blogs

Disclaimer

The contents in this blog are taken from various sources available over the internet, therefore we do not gurantee of it's accuracy, if you find any of the content in the blog is infringing it's copyright, please do email us on '123techguide@gmail.com' and we will make sure to remove the same from the blog at the earliest.