用C写的读取代码行数。
今天无事,在论坛上一直看贴子,很少动手实践,今天试着写了一个读取源程序代码行数的例子:
现在的代码如下,可能还有不完善的地方,以后再改进:
#include <stdio.h>
#define CHARCOUNT 255
#define CON 6 /*单行注释最少的时候*/
int realLength = 0;
/*
* function name: strCount
* function : count line number
* created by : lsl
*/
int strCount(int from, char * str)
{
int length = strlen(str), i = 0;
int realCount = length-2-from;
for(i = length-3; str[i]==' ' || str[i] ==' '; i--)
{
realCount--;
}
realLength = realCount;
return realLength;
}
int main(int argc, char *argv[])
{
FILE *fPtr = fopen("tt.c","r");
char buffer[CHARCOUNT];
int lineCount = 0,i=0,j=0,k=0,bufferLen = 0;
int moutLineComment = 0;
if(NULL == fPtr)
{
printf("file open error!\n");
exit(0);
}
while(NULL != fgets(buffer,CHARCOUNT,fPtr))
{
//如果只包含一上回车 begin
if(13 == buffer[0] && 10 == buffer[1])
{
//printf("%x%x\n",buffer[0],buffer[1]);
continue;
}
//如果只包含一个回车 end
else
{
bufferLen = strlen(buffer);//读入行的长度 算上读入末尾的 \n\r
//判断一行为空行的情况 此行可能包含许多空格 tab begin
for(i = 0; 32 == buffer[i] || 9 == buffer[i] || 13 == buffer[i] || 10 == buffer[i]; i++ )
{
if(i == bufferLen)
{
break;
}
}
if(bufferLen == i)
{
continue;
}
//判断一行为空行的情况 end
//判断//注释 begin
else if(buffer[i] == '/' && buffer[i+1] == '/')
{
continue;
}
//判断//注释 end
//判断多行注释 begin
else if(buffer[i] == '/' && buffer[i+1] == '*')
{
//**/rin tf("here\n");
if((bufferLen-i)>=CON)
{
int tmpLen = strCount(i,buffer);//求出此行从i开始除最后的空格、\r\n之外的字符数
if((tmpLen>=4) && buffer[i+tmpLen-2] == '*' && buffer[i+tmpLen-1] == '/')
{
continue;
}
else
{
相关文档:
内容:Introduction 和 Error Reporting
1. glibc 所实现全部或部分规范下的功能有
ISO C: The international standard for the C programming language.
POSIX: The ISO/IEC 9945 (aka IEEE 1003) standards for operating systems.
Berkeley Unix: BSD and SunOS.
SVID: The System V Interface Description.
X ......
在Notes 的C/S 编程中,经常需要对一个集合中的对象进行遍历处理,这时如果能显示一个进度条指示当前处理进程,就比较直观形象,客户界面也比较友好。
1、声明API函数
'声明API函数
Declare Function NEMProgressBegin Lib&nbs ......
C程序是由一组或是变量或是函数的外部对象组成的。 函数是一个自我包含的完成一定相关功能的执行代码段。下面小编和大家分享下C语言中的函数。
1. kbhit函数
kbhit函数是检查当前按下的键,其用法为:int kbhit(void);程序例子如下:
#include <conio.h>
int main(void)
{
c ......
unzip.c
中引用validate.cpp
文件中的函数来进行epub
纠错,产生的问题:
1.
validate.cpp
中使用iostream.h,
但是C
中没有这个文件
,所以产生的错误:
2>
正在编译...
2>unzip.c
2>D:\Program
Files\VC\include\cstdio(25) : error C2143:
语法错误:
缺少“{ ......