1 /*
2 * 没能实现的功能:wc.exe -s递归处理目录下符合条件的文件
3 * wc.exe -x 显示图形界面
4 *
5 *
6 * 实现的功能: wc.exe -c显示文件的字符数、
7 * wc.exe -l行数、
8 * wc.exe -w单词、
9 * wc.exe -a空行数、代码行数、注释行数的统计测试
10 *`
11 *
12 */
13
14 #include"iostream"
15 using namespace std;
16 void CharCount(char path[]); //字符统计函数
17 void WordCount(char path[]); //单词统计函数
18 void LineCount(char path[]); //行数统计函数
19 void Muiltiple(char path[]); //综合统计函数,包括代码行,空行,注释行
20 int main()
21 {
22 char input[100],path[50];
23 gets(input);
24 int count=strlen(input);
25 strncpy(path, input + 10, count - 10);
26 path[count - 9] = '\0';
27 //cout << path << endl;
28 int check = 1;
29 while (check)
30 {
31 int i = 7;
32 if ((input[i] == '-') && (input[i + 1] == 'c'))
33 {
34 CharCount(path);
35 break;
36 }
37 if ((input[i] == '-') && (input[i + 1] == 'w'))
38 {
39 WordCount(path);
40 break;
41 }
42 if ((input[i] == '-') && (input[i + 1] == 'l'))
43 {
44 LineCount(path);
45 break;
46 }
47 if ((input[i] == '-') && (input[i + 1] == 'a'))
48 {
49 Muiltiple(path);
50 break;
51 }//获取文件名
52 }
53 system("pause");
54 return 0;
55 }
56 void CharCount(char path[]) //字符统计函数
57 {
58 FILE *fp=NULL;
59 int c = 0;
60 char ch;
61 cout << path<<endl;
62 char *path3 = path;
63 int k = strlen(path);
64 *(path3 + k-1) = '\0';
65 //cout << path3<<endl;
66 if ((fp = fopen(path3 , "r")) == NULL)
67 {
68 printf("file read failure.");
69 exit(0);
70 }
71 ch = fgetc(fp);
72 while (ch != EOF)
73 {
74 c++;
75 ch = fgetc(fp);
76 }
77 cout << "char count is :" << c << endl;
78 c--;
79 fclose(fp);
80 }
81
82 void WordCount(char path[]) //单词统计函数
83 {
84 FILE *fp;
85 int w = 0;
86 char ch;
87 char *path3 = path;
88 int k = strlen(path);
89 *(path3 + k - 1) = '\0';
90 if ((fp = fopen(path3, "r")) == NULL)
91 {
92 printf("file read failure.");
93 exit(0);
94 }
95 //fgetc()会返回读取到的字符,若返回EOF则表示到了文件尾,或出现了错误。
96 ch = fgetc(fp);
97 while (ch != EOF)
98 {
99 if ((ch >= 'a'&&ch <= 'z') || (ch >= 'A'&&ch <= 'Z') || (ch >= '0'&&ch <= '9'))
100 {
101 while ((ch >= 'a'&&ch <= 'z') || (ch >= 'A'&&ch <= 'Z') || (ch >= '0'&&ch <= '9') || ch == '_')
102 {
103 ch = fgetc(fp);
104 }
105 w++;
106 ch = fgetc(fp);
107 }
108 else
109 {
110 ch = fgetc(fp);
111 }
112 }
113 printf("word count is :%d.\n", w);
114 fclose(fp);
115
116 }
117
118 void LineCount(char path[]) //行数统计函数
119 {
120 FILE *fp;
121 int l = 1;
122 char ch;
123 char *path3 = path;
124 int k = strlen(path);
125 *(path3 + k - 1) = '\0';
126 if ((fp = fopen(path3, "r")) == NULL)
127 {
128 printf("file read failure.");
129 exit(0);
130 }
131 //fgetc()会返回读取到的字符,若返回EOF则表示到了文件尾,或出现了错误。
132 ch = fgetc(fp);
133 while (ch != EOF)
134 {
135 if (ch == '\n')
136 {
137 l++;
138 ch = fgetc(fp);
139 }
140 else
141 {
142 ch = fgetc(fp);
143 }
144 }
145 l--;
146 printf("line count is :%d.\n", l);
147 fclose(fp);
148 }
149
150 void Muiltiple(char path[]) //综合统计函数,包括代码行,空行,注释行
151 {
152 FILE *fp;
153 char ch;
154 char *path3 = path;
155 int k = strlen(path);
156 *(path3 + k - 1) = '\0';
157 int c = 0, e = 0, n = 0;
158 if ((fp = fopen(path3, "r")) == NULL)
159 {
160 printf("file read failure.");
161 exit(0);
162 }
163 //fgetc()会返回读取到的字符,若返回EOF则表示到了文件尾,或出现了错误。
164 ch = fgetc(fp);
165 while (ch != EOF)
166 {
167 if (ch == '{' || ch == '}')
168 {
169 e++;
170 ch = fgetc(fp);
171 }
172 else if (ch == '\n')
173 {
174 ch = fgetc(fp);
175 while (ch == '\n')
176 {
177 e++;
178 ch = fgetc(fp);
179 }
180 }
181 else if (ch == '/')
182 {
183 ch = fgetc(fp);
184 if (ch == '/')
185 while (ch != '\n')
186 {
187 ch = fgetc(fp);
188 }
189 n++;
190 ch = fgetc(fp);
191 }
192 else
193 {
194 c++;
195 while (ch != '{'&&ch != '}'&&ch != '\n'&&ch != '/'&&ch != EOF)
196 {
197 ch = fgetc(fp);
198 }
199 }
200
201 }
202 printf("code line count is :%d.\n", c);
203 printf("empt line count is :%d.\n", e);
204 printf("note line count is :%d.\n", n);
205 fclose(fp);
206 }

wc.exe的更多相关文章

  1. WC.exe【C】

    gitee传送门!!!(电脑打不开github,多次尝试未果,决定先用gitee存着先) 项目要求 wc.exe 是一个常见的工具,它能统计文本文件的字符数.单词数和行数.这个项目要求写一个命令行程序 ...

  2. 小白のjava实现wc.exe功能

    GitHub地址 项目完成情况 基本功能列表(已实现) wc.exe -c file.c     //返回文件 file.c 的字符数 wc.exe -w file.c    //返回文件 file. ...

  3. 模仿WC.exe的功能实现--node.js

    Github项目地址:https://github.com/102derLinmenmin/myWc WC 项目要求 wc.exe 是一个常见的工具,它能统计文本文件的字符数.单词数和行数.这个项目要 ...

  4. 软工作业1—java实现wc.exe

    github项目地址 https://github.com/liyizhu/wc.exe WC 项目要求 基本功能列表: wc.exe -c file.c     //返回文件 file.c 的字符数 ...

  5. 用c语言基本实现wc.exe功能

    网址:https://github.com/3216005214/wc.exe wc项目要求 wc.exe 是一个常见的工具,它能统计文本文件的字符数.单词数和行数.这个项目要求写一个命令行程序,模仿 ...

  6. java实现wc.exe

    Github地址:https://github.com/ztz1998/wc/tree/master 项目相关要求 实现一个统计程序,它能正确统计程序文件中的字符数.单词数.行数,以及还具备其他扩展功 ...

  7. (第三周)wc.exe—命令行实现对指定目录下文件的操作

    一.用户需求 程序处理用户需求的模式为: wc.exe [parameter][filename] 在[parameter]中,用户通过输入参数与程序交互,需实现的功能如下: 1.基本功能 支持 -c ...

  8. 软工作业No.1。Java实现WC.exe

    网址:https://github.com/a249970271/WC WC 项目要求 wc.exe 是一个常见的工具,它能统计文本文件的字符数.单词数和行数.这个项目要求写一个命令行程序,模仿已有w ...

  9. 软件工程 wc.exe 代码统计作业

    软件工程 wc.exe 代码统计作业分享 1. Github 项目地址 https://github.com/EdwardLiu-Aurora/WordCount 更好地阅读本文,可点击这里 基本要求 ...

随机推荐

  1. KAFKA跨主机部署网络不通解决思路

    Kafka的部署不仅需要集群可用,同时需要对orderer节点可连,这就是为什么有的时候,kafka集群本身没问题,但是orderer却总是报错. 为了试验kafka剥离方案的可行性,跨阿里云网络和内 ...

  2. IBase<T>

    public interface IBase<T>//基类 { IEnumerable<T> SelectAll();//查询所有 T FindById(int ID);//根 ...

  3. ubuntu 创建文件夹和删除文件

    创建 名为docker的文件夹 :mkdir docker 删除 名为docker的文件夹 : rm docker 创建名为docker-compose.yml的文件 : vi docker-comp ...

  4. node.js 生成二维码

    因为自己的项目中,想在商品详情页上 显示一个 商品优惠券的二维码. 以此为需求. node.js 后台代码 const qr_image = require("qr-image") ...

  5. vue中是使用富文本编辑器vue-quill-edit

    之前使用的富文本编辑器是uEditor,kindEditor,感觉不太方便 近期项目vue单页面,就使用这个编辑器组件吧! 一.安装  cnpm install vue-quill-editor 二. ...

  6. FPM五:拆解前面的四——OVP做查询和结果

    说明:前面的例子是将list和search放到一个Feeder Class里的,这里来做拆解分步说明. 1.创建SEARCH的结构 2.创建RESULT的结构 表类型(不用表类型的话,需要自己在cla ...

  7. JavaScript前端面试题总结

    1.em和rem 像素(px):用于元素的边框或定位. em/rem:用于做响应式页面,em相对于父元素,rem相对于根元素. rem 单位翻译为像素值是由 html 元素的字体大小决定的. 此字体大 ...

  8. 洛谷P3627[APOI2009] (讨厌的)抢掠计划

    题目描述 Siruseri 城中的道路都是单向的.不同的道路由路口连接.按照法律的规定, 在每个路口都设立了一个 Siruseri 银行的 ATM 取款机.令人奇怪的是,Siruseri 的酒吧也都设 ...

  9. Jenkins自动构建gitlab项目(jenkins+maven+giltlab+tomcat)

    环境准备: System:CentOS 7.3 (最小化安装) JDK: 8u161 (1.8_161) tomcat: 8.5.29 Jenkins: Jenkins 2.107.1 Gitlab: ...

  10. Xshell配置使用linux的图形界面

    1.配置Xshell如下图 2.在命令行中执行"gnome-panel". 3.或者使用xstart,配置如下图: