Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2508660
  • 博文数量: 308
  • 博客积分: 5547
  • 博客等级: 大校
  • 技术积分: 3782
  • 用 户 组: 普通用户
  • 注册时间: 2009-11-24 09:47
个人简介

hello world.

文章分类

全部博文(308)

分类: C/C++

2011-03-23 08:20:29

为了统计我们所输入的字符进行统计,一般我们都会编写一个程序进行统计,一般的原理就是。循环录入字符当遇到结束符号的时候停止结束,在循环的外部定义变量,根据ascill码,对录入的字符进行统计。代码如下:
  1. #include <string.h>
  2. #include <stdio.h>

  3. int main(int argc, char* argv[])
  4. {
  5.   char c;
  6.   int space = 0, table = 0, enter = 0;
  7.   printf("please input a string:\n");
  8.   scanf("%c",&c);
  9.   
  10.   while(c != EOF)
  11.   {
  12.     switch(c)
  13.     {
  14.       case 32: space++; break;
  15.       case 9: table++; break;
  16.       case 10: enter++; break;
  17.       default:break;
  18.     }
  19.     scanf("%c",&c);
  20.   }
  21.   
  22.   printf("the number of space:%d\n", space);
  23.   printf("the number of table:%d\n", table);
  24.   printf("the number of enter:%d\n", enter);
  25.   getchar();
  26.   return 0;
  27. }
阅读(1308) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~