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

王林
Release: 2023-08-25 23:53:12
forward
1562 people have browsed it

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;
}
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template