Find number of occurrences of character in string

Write a C program to read a string and count number of occurrences of entered character.

Solution:

#include<stdio.h>
    int main()
    {
        char str2[30],ch;
        int i,count=0;
        printf("Enter the string: ");
        gets(str2);
        printf("\nEnter character from string that you want to find: ");
        scanf("%c",&ch);
        for(i=0;str2[i]!='\0';i++)
        {
            if(ch==str2[i])
            {
                count++;
            }
        }
        printf("\n'%c' Occurs '%d' Times",ch,count);
        return 0;
    }


Output:

occurrence character