代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
AS
】
C语言代码统计工具
作者:
saintatgod
/ 发布于
2015/8/19
/
1409
统计指定路径下的 .C 以及 .h 文件 的代码总行数,有效行数,注释行数,空行数。
// #include "stdafx.h" #include "stdafx.h" #include <windows.h> #include <string.h> #include <io.h> #include "stdlib.h" #include "time.h" static int a1 = 0; static int a2 = 0; static int a3 = 0; static int a4 = 0; int _tmain(int argc, _TCHAR* argv[]) { clock_t start,finish; double duration; void File_Process(char k[]); void File_Check(char kik[], char kk[],char kos []); void File_Chose( char kik[], char kk[], char kos []); FILE *fp; int work = 1; while(work) { a1 = 0, a2 = 0, a3 = 0, a4 = 0; char kk[50] = {"\0"}; char kik[50] = {"\0"}; char kos[50] = {"\0"}; printf("Enter the path or file path of the folder : "); scanf("%s", kk); start = clock(); File_Chose(kik, kk, kos); finish = clock(); duration = (double)(finish - start) / CLOCKS_PER_SEC; printf( "%f seconds\n", duration ); printf("Whether exit the count system?(1 is not exit,0 is exit)\n"); //whether exit the system. scanf("%d", &work); fflush(stdin); while (work != 0 && work != 1) //kik must is 1 or 0. { printf(" Input is error,Please input again!\n"); scanf("%d", &work); fflush(stdin); } } printf("\n--------------------Thanks For You Using The Count System !--------------------\n"); Sleep(2000); //deley some times. return 0; } /*void File_Process(char k[]) { char a[20][10] = {'0'}; FILE *fp; char ch ; int i = 0, kl = 0, kk = 0, j = 0; bool sign = 0; if( (fp = fopen(k, "r") ) == NULL) { printf("open is error!\n"); exit(0); } while( ( ch = fgetc(fp) ) != EOF) { if(ch == '\n' ) { kl++; if( (ch = fgetc(fp) ) !=EOF ) { if(ch == '\n') { kk++; kl++; } } } if(ch == '/') { if( ( ch = fgetc(fp) ) != EOF ) { if( (ch == '/' || ch == '*') ) { i++; sign = 1; } } if(ch == '\n') { kl++; } } if(ch == '*') { if( ( ch = fgetc(fp) ) != EOF ) { if( ( ch == '/' && sign ) ) { i++; sign = 0; } } if(ch == '\n') { kl++; } } } putchar('\n'); printf("注释行数:%d 空行数:%d 总行数:%d 有效代码行:%d\n", i, kk, kl,(kl-kk-i)); fclose(fp); } */ /*void File_Process(char k[]) { char a[][100] = {'0'}; FILE *fp; char ch ; int i = 0, kl = 0, kk = 0, j = 0; bool sign = 0; if( (fp = fopen(k, "r") ) == NULL) { printf("open is error!\n"); exit(0); } while( ( ch = fgetc(fp) ) != EOF) { if('\n' == ch) { a[i][j++] = '\0'; i++; j = 0; } while('\n' != ch) { a[i][j++] = ch; if( ( ch = fgetc(fp) ) == EOF ) { printf("the file is end!"); exit(0); } if('\n' == ch) { i++; j = 0; if( ( ch = fgetc(fp) ) == EOF ) { printf("the file is end!"); exit(0); } } if('\n' == ch) { a[i][j++] = '\0'; i++; j = 0; } } i++; j = 0; } }*/ void File_Process(char k[]) { int zong = 0, zhushi = 0, kong = 0; int tt = 0; char a[1000] = {'\0'}; FILE *fp; char ch ; static bool sign = 0; static int kk = 0; if( (fp = fopen(k, "r") ) == NULL) { printf("open is error!\n"); exit(0); } int j = 0; while( ( ch = fgetc(fp) ) != EOF) { if(ch != '\n') { a[j++] = ch; continue; } if(sign == 1) { kk++; } zong++; if ( 0 == strlen (a) ) { kong++; } for(int i = 0; i < j; ++i) { if( ( '/' == a[i] && '*' == a[i+1] ) && ('*' == a[j-2] && '/' == a[j-1] ) ) { zhushi++; } else if( ('/' == a[i] && '*' == a[i+1] ) && ('*' != a[j-2] && '/' != a[j-1] ) ) { sign = 1; k++; } else if('*' == a[i] && '/' == a[i+1] && sign == 1) { zhushi += kk; kk = 0; sign = 0; } else if('/' == a[i] && '/' == a[i+1] ) { zhushi++; } } a[j] = '\0'; a[0] = '\0'; j = 0; } putchar('\n'); printf("注释行数:%d 空行数:%d 总行数:%d 有效代码行:%d\n", zhushi, kong, zong,(zong-kong-zhushi)); a1 += zhushi, a2 += kong, a3 += zong, a4 += (zong - kong - zhushi); fclose(fp); } void File_Check(char kik[], char kk[], char kos []) { //strcat(kik, "\\*.cpp"); long Handle; struct _finddata_t FileInfo; if((Handle = _findfirst(kik,&FileInfo)) == -1L) { printf("没有找到匹配的项目\n"); exit(0); } else { printf("%s\n",FileInfo.name); File_Process(kk); while(_findnext(Handle,&FileInfo) == 0) { char koos[50] = {"\0"}; strcat(koos,kos); strcat(koos,FileInfo.name); printf("%s\n",FileInfo.name); File_Process(koos); } _findclose(Handle); } } void File_Check1(char kik[], char kk[], char kos []) { //strcat(kik, "\\*.cpp"); long Handle; struct _finddata_t FileInfo; if((Handle = _findfirst(kik,&FileInfo)) == -1L) { printf("没有找到匹配的项目\n"); exit(0); } else { strcat(kk,"\\"); strcat(kos,kk); strcat(kk, FileInfo.name); printf("%s\n",FileInfo.name); File_Process(kk); while(_findnext(Handle,&FileInfo) == 0) { char koos[50] = {"\0"}; strcat(koos,kos); strcat(koos,FileInfo.name); printf("%s\n",FileInfo.name); File_Process(koos); } _findclose(Handle); } } void File_Chose( char kik[], char kk[], char kos []) { int a = 0; if('d' != kk[0] && 'D' != kk[0] && 'c' != kk[0] && 'C' != kk[0] && 'e' != kk[0] && 'E' != kk[0]) { printf("fan fu you wu!\n"); exit(0); } if( ':' != kk[1] ) { printf("lu jing ge shi you wu!\n"); exit(0); } a = strlen(kk); if ( (kk[a-2] == '.') && ( ( kk[a-1] =='C' || kk[a-1] == 'c') || (kk[a-1] == 'H' || kk[a-1] == 'h') ) ) { strcpy(kik, kk); File_Check( kik, kk, kos); } else { strcat(kik, kk); strcat(kik, "\\*.c"); File_Check1(kik, kk, kos); putchar('\n'); printf("总注释行数:%d 总空行数:%d 总行数:%d 总有效代码行:%d\n", a1, a2, a3,a4); } }
试试其它关键字
代码统计
同语言下
.
C语言代码统计工具
.
排序集合中的元素
.
显示和隐藏隐含文件
.
ActionScript将颜色转换成16进制
.
把应用程序标题设置为版本号
.
异步读取文件
.
生成指定范围的随机数
.
定时器范例
.
返回当前SWF文件所在页面的url
.
通过get方式发送或者请求数据
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
saintatgod
贡献的其它代码
(
6
)
.
保存excel文件
.
C语言代码统计工具
.
将文件流生成缩略图,并分发到fastDFS
.
二分查找
.
通过api获取访问的ip来源
.
一个关于聊天机器人的调用
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3