首页 > 其他 > 详细

练习1-11 如何测试单词计数程序?如果程序中存在某种错误,那么什么样的输入最可能发现这类错误呢?

时间:2020-04-23 22:49:58      阅读:84      评论:0      收藏:0      [点我收藏+]
 1 #include <stdio.h>
 2  
 3 #define IN    1
 4 #define OUT 0
 5 
 6 /*统计各个数字、空白符及其他字符出现的次数*/
 7  
 8 int main()
 9 {
10     int c, n1, nw, nc, state;
11  
12     state = OUT;
13     n1 = nw = nc = 0;
14  
15     while ((c = getchar()) != EOF)
16     {
17         ++nc;
18         if (c == \n)
19             ++n1;
20  
21         if (c ==   || c == \n || c == \t)
22         {
23             state = OUT;
24         }
25  
26         else if (state == OUT)
27         {
28             state = IN;
29             ++nw;
30         }
31     }
32  
33     printf("%d %d %d \n", n1, nw, nc);
34 }

此程序对于单词的定义比较宽松,假设一个!标点左右都为空格时,这个标点也会被判定为单词

练习1-11 如何测试单词计数程序?如果程序中存在某种错误,那么什么样的输入最可能发现这类错误呢?

原文:https://www.cnblogs.com/liuhaiqing/p/12764310.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!