现在好好好学习小甲鱼老师的C语言
{:10_254:}
{:5_90:}
{:5_91:}
学习一下!!!
答案
看看
我还是新手
弄完了,边写边想是什么意思,有些地方不懂该怎么理解,截图 如下:
还有想问下小甲鱼,为何前面定义是void findALLFiles(const char *pach);
而后面用的是 void findALLDirs(const char *path)
为何我是94行。。。。。。难道 哪里抄错了
等等
目前你总共写了97行代码!
亲们趁敌人吃饭时发动进攻
0因为计算机只能识别二进制
1机器语言
2编译
3一个是直接翻译一个是间接翻译
4不能
5借助翻译
6(-。-;)
7q i n m e n
c h e n d
i r e n c
h i f a n
s h i f
a d o n g
j i n g o
a g
亲们
趁敌人吃饭
事发东京oag
看答案
嘿嘿
抄答案{:5_91:}
发现代码还是会异常,tab没处理好!,,T
老报错!!!!!
#include <io.h>
#include <direct.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 256
long total;
int countLines(const char *filename);
void findAllCodes(const char *path);
void findALLFiles(const char *path);
int countLines(const char *filename)
{
FILE *fp;
int count = 0;
int temp;
if ((fp = fopen(filename,"r")) == NULL)
{
fprintf(stderr,"Can not open the file: %s\n",filename);
return 0;
}
while ((temp = fgetc(fp)!=EOF))
{
if(temp == '\n')
{
count++;
}
}
fclose(fp);
return count;
}
void findALLCodes(const char *path)
{
struct _finddata_t fa;
long handle;
char thePath,target;
strcpy(thePath,path);
if((handle = _findfirst(strcat(thePath,"/*.c"),&fa)) !=-1L)
{
do
{
sprintf(target,"%s/%s",path,fa.name);
total +=countLines(target);
}while (_findnext(handle,&fa) == 0);
}
_findclose(handle);
}
void findALLDirs(const char *path)
{
struct_finddata_t fa;
long handle;
char thePath;
strcpy(thePath, path);
if((handle = _findfirst(strcat(thePath,"/*"), &fa)) == -1L)
{
fprintf(stderr,"The path %s is wrong!\n",path);
return;
}
do
{
if(!strcmp(fa.name,".")|| !strcmp(fa.name,".."))
continue;
if(fa.attrib == _A_SUBDIR)
{
sprintf(thePath,"%s%s",path,fa.name);
findALLCodes(thePath);
findALLDirs(thePath);
}
}while (_findnext(handle,&fa) ==0);
_findclose(handle);
}
int main()
{
char path = ".";
printf("计算中……\n");
findALLCodes(path);
findALLDirs(path);
printf("目前你总共写了 %1d 行代码!\n\n ", total);
system("pause");
return 0;
}