Advertisement
Guest User

Untitled

a guest
Feb 19th, 2020
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.68 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5.     char    str[100];
  6.     int countAlphabet,countSpecialChar,countSpaces;
  7.     int counter;
  8.  
  9.     countAlphabet=countSpecialChar=countSpaces=0; //all counters to zero
  10.  
  11.     printf("Enter a string: ");
  12.     gets(str);
  13.  
  14.     for(counter=0;str[counter]!=NULL;counter++)
  15.     {
  16.  
  17.         if((str[counter]>='A' && str[counter]<='Z')||(str[counter]>='a' && str[counter]<='z'))
  18.             countAlphabet++;
  19.         else if(str[counter]==' ')
  20.             countSpaces++;
  21.         else
  22.             countSpecialChar++;
  23.     }
  24.  
  25.     printf("Alphabets: %d \nSpaces: %d \nSpecial Characters: %d",countAlphabet,countSpaces,countSpecialChar);
  26.  
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement