Advertisement
R3v3rs3r

Program to display the occurrence of a character in a given string

Apr 2nd, 2023
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.48 KB | Source Code | 0 0
  1. #include<stdio.h>
  2. #include<conio.h>
  3. #include<string.h>
  4.  
  5. int main()
  6. {
  7.     char str[30], ch;
  8.     int i, count=0;
  9.    
  10.     printf("Enter a string: ");
  11.     scanf("%[^\n]%*c", &str);
  12.    
  13.     printf("\nEnter character to be searched: ");
  14.     scanf("%c", &ch);
  15.    
  16.     for(i=0; i<strlen(str); i++)
  17.     {
  18.         if(str[i]==ch)
  19.         {
  20.             ++count;
  21.         }
  22.     }
  23.     printf("\nCharacter '%c' occurs %d times", ch, count);
  24.    
  25.     getch();
  26.     return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement