C Program To Count The Occurrence Of A Given Character In A String


Program Code:

#include <stdio.h>
#include <string.h>
int main()
{
    char s[1000],c;  
    int i,count=0;
    printf("Enter  the string : ");
    gets(s);
    printf("Enter character to be searched: ");
    c=getchar();
    for(i=0;s[i];i++)  
{
    if(s[i]==c)
    	{
          count++;
	} 
}
	printf("character '%c' occurs %d times \n ",c,count);
	return 0;
}


To learn more about programming and coding visit our website. PDF study materials also available on our website.

Log on to: www.thecode11.com