我来看答案了
#include <stdio.h>
#include <unistd.h>
#include <dirent.h>
#include <string.h>
#include <stdlib.h>
#include <sys/stat.h>
#define MAX 256
long total;
int countlines(const char *filename);
int isCode(const char *filename);
void findALLDirs(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;
}
int isCode(const char *filename)
{
int length;
length = strlen(filename);
if (!strcmp(filename + (length - 2), ".c"))
{
return 1;
}
else
{
return 0;
}
}
void findALLDirs(const char *path)
{
DIR *dp;
struct dirent *entry;
struct stat statbuf;
if ((dp = opendir(path)) == NULL)
{
fprintf(stderr, "The path %s is wrong!\n",path);
return;
}
chdir(path);
while ((entry = readdir(dp)) != NULL)
{
lstat(entry->d_name, &statbuf);
if(!strcmp(".", entry->d_name) || !strcmp("..", entry->d_name))
continue;
if (S_ISDIR(statbuf.st_mode))
{
findALLDirs(entry->d_name);
}
else
{
if (isCode(entry->d_name))
{
total += countlines(entry->d_name);
}
}
}
chdir("..");
clearerr(dp);
}
int main()
{
char path = ".";
printf("计算中...\n");
findALLDirs(path);
printf("目前你总共写了 %ld 行代码!\n\n", total);
return 0;
}
初学者报道!!!!
瞧瞧
?
#include <io.h>
#include <direct.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 256
long total;
int countLines(const char *fukename);
void findAllCodes(const char *path);
void findAllFiles(const char *path);
int countLine(const char *filename)
{
FILE *fp;
int count = 0;
int temp;
if((fp = fopen(fukename), "r")) == NULL)
{
fprintf(stderr, "Can not open the file:%s\n", filename);
return 0;
}
while ((temp = fgetc(fo)) !=EOF)
{
if (temp =='\n')
{
count==;
}
}
fclose(fp);
feturn count;
}
void findAllCodes(const char *path)
{
struct _finddata_t fa;
long handle;
char thePath, target;
strcpy(thePath, path);
if((handle = _findfirst(strcat(the Path, "/*.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("¼ÆËãÖD...\n");
findAllCodes(path);
findALLDirs(path);
printf("ĿǰÄã×ü12D′áË %ld DD′úÂë! \n\n", total);
system("pause");
return 0;
}
感謝小甲魚
好人一生平安
{:5_109:}
lail
s
感谢小甲鱼!!!
那个代码真的敲得我头秃
好难
huifu
9999999
看答案先
完成
0.因为计算机只认识0和1两个数
1.汇编语言
2.编译
3.执行过程不一样,编译型语言经过编译后直接执行编译得到的汇编代码;而解释型语言由解释器翻译执行;所以编译型语言的效率更高
4.不能
5.解释型语言跨平台需要预装解释器
6.摩斯密码是通过长短信号相当于0和1的排列组合定义出字符集,通信过程中先翻译为代码组合再截石位字符
7.QIN MEN CHEN DI REN CHI FAN SHI FA DONG JIN GONG
1.机器语言
2.编译