C language statistics A string of characters the space bar, TAB key, enter, letters, numbers and other characters (CTRL + Z terminating input)

Source: Internet
Author: User

Kerugaki-Blog Park http://www.cnblogs.com/kailugaji/

1#include <stdio.h>2 3 voidMain () {4     intC, letter=0, num=0, blank=0, tab=0, enter=0, other=0, i=0, sum=0;5printf"Please input a string:\n");6      while((C=getchar ())! =EOF) {7sum++;8         if(c==' '){9++blank;//the number of space barTen         } One         Else if(c=='\ t'){ A++tab;//Number of tab keys -         } -         Else if(c=='\ n'){ the++enter;//number of Enter key -         } -         Else if((c>='A'&& c<='Z') || (c>='a'&& c<='Z')){ -++letter;//Number of letters +         } -         Else if(c>='0'&& c<='9'){ +++num;//Number of Numbers A         } at         Else++other;//number of other characters -i++; -     } -printf"there is%d characters\n", sum); -printf"blank=%d, tab=%d, enter=%d, letter=%d, number=%d, other=%d\n", blank, tab, enter, letter, NUM, and other); -  in}

The result is:

C language statistics A string of characters the space bar, TAB key, enter, letters, numbers and other characters (CTRL + Z terminating input)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.