用VS测试程序
2016-03-21 19:45
274 查看
怀着一种忐忑的心情,我开始了我的软件测试。
其实只是一个比较简单的程序,当时写完我还感到一丝的不可思议,因为它实在是太短了。竟然完成了我想要的功能,看来开始是我想复杂了,哎,没头脑呀!
这是wang.txt
这是运行结果。
我想把这个程序完善一下,因为当出现连续的非英文字符时(如:,,,, 。。。。)单词的数目会出现错误,我想见一个链表进行数据的存储,然后方便前后的字符进行比较。可我觉得这个方法太麻烦了,哪位大神还有更好的方法,欢迎指教呀!
#include "stdio.h" #include "stdlib.h" int main(int argc, char* argv[]) { FILE *fp; bool flag = false; char ch; int count = 0,word = 0,line = 0; fp=fopen ("wang.txt","r"); if (fp==NULL) { printf ("the file:wang.txt not found\n"); exit (-1); } if((ch=fgetc(fp))!=EOF) { line++; count++; } while ( (ch=fgetc(fp))!=EOF) { count++; if ((ch<'a'||ch>'z')&&(ch<'A'||ch>'Z')) { word++; flag = false; } else { flag = true; } if (ch=='\n') line++; } if(flag){ word++; } printf("字符为:%d\n",count); printf("单词为:%d\n",word); printf("行数为:%d\n",line); fclose(fp); return (0); }
其实只是一个比较简单的程序,当时写完我还感到一丝的不可思议,因为它实在是太短了。竟然完成了我想要的功能,看来开始是我想复杂了,哎,没头脑呀!
这是wang.txt
这是运行结果。
我想把这个程序完善一下,因为当出现连续的非英文字符时(如:,,,, 。。。。)单词的数目会出现错误,我想见一个链表进行数据的存储,然后方便前后的字符进行比较。可我觉得这个方法太麻烦了,哪位大神还有更好的方法,欢迎指教呀!
相关文章推荐
- Adobe illustrator & Photoshop 处理图片
- 在windows下搭建linux-c学习环境
- 第十讲--Oracle日志原理剖析
- 在windows下搭建linux-c学习环境
- 《HiWind企业快速开发框架实战》(0)目录及框架简介
- ABP源码分析八:Logger集成
- 排序
- android studio 使用、开发小技巧
- UTF-8编码中的BOM问题
- RESTful API 设计指南
- 网易编程一题个人代码
- index of("") ==-1
- codevs 2645 Spore
- 总结……c++的输出格式
- 何为幂等可重试(安全操作)
- Biorhythms(一元线性同余方程组)
- 宽带连接批处理文件
- iOS中使用 Reachability 检测网络
- NSString转化为UTF8
- 如何在eclipse中安装subclipse