Home >Backend Development >C++ >Count the number of spaces, uppercase letters, and lowercase letters in a sentence using C

Count the number of spaces, uppercase letters, and lowercase letters in a sentence using C

王林
王林forward
2023-08-25 23:53:121593browse

Count the number of spaces, uppercase letters, and lowercase letters in a sentence using C

#include
int main() {
   char str[100],i;
   int upper = 0, lower = 0, number = 0, special = 0,whitesp=0;
   printf("enter string");
   gets(str);
   for (i = 0; i < str[i]!=&#39;\0&#39;; i++) {
      if (str[i] >= &#39;A&#39; && str[i] <= &#39;Z&#39;)
         upper++;
      else if (str[i] >= &#39;a&#39; && str[i] <= &#39;z&#39;)
         lower++;
      else if (str[i]>= &#39;0&#39; && str[i]<= &#39;9&#39;)
         number++;
      else if(str[i]==&#39; &#39;)
         whitesp++;
      else
         special++;
   }
   printf("Upper case letters: %d</p><p>",upper);
   printf("lower case letters: %d</p><p>",lower);
   printf("Numbers: %d</p><p>",number);
   printf("whitespace: %d</p><p>",whitesp);
   printf("sp chararcter: %d</p><p>",special);
   return 0;
}

The above is the detailed content of Count the number of spaces, uppercase letters, and lowercase letters in a sentence using C. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete