Count the Number of Occurrences of Any Character from Input String

  1. #include<stdio.h>  
  2. #include<conio.h>  
  3. main()  
  4.     {  
  5.     char string[150], Mychar;  
  6.     int count=0, j=0;  
  7.     printf("Please enter a string:\n");  
  8.     gets(string);  
  9.     printf("Please enter the character for find occurances of that: \t");  
  10.     scanf("%c", &Mychar);  
  11.     while(string[j]!='\0')  
  12.     {  
  13.         if(string[j]==Mychar)  
  14.         count++;  
  15.         j++;  
  16.     }  
  17.     printf("Above string contains %c occurred %d times \n",Mychar, count);  
  18.     getch();  
  19. }