作业
1
135行
甲鱼回复我一下,我写出来后运行显示0行代码。求求求求解答
小甲鱼下面是我写的代码 为什么计算出来是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 *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 worng!\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("目前你总共写了 %ld 行代码! \n\n", total);
system("pause");
return 0;
}
hhh
看答案
0
答案
抄也是个技术活{:5_99:}
顶顶顶!!!
{:5_108:}
本帖最后由 顾小伟 于 2020-3-11 09:30 编辑
测试题:
0.计算机只认识0和1这两个数字;
1.机器语言,也叫汇编语言;
2.编译;
3.编译型语言在程序执行之前,有一个单独的编译过程,将程序翻译成机器语言,以后执行这个程序的时候,就不用再进行翻译了;解释型语言,是在运行的时候将程序翻译成机器语言,所以运行速度相对于编译型语言要慢;
4.可以在windows执行;
5.通过不同的解释器解释就能在不同的平台使用;
6.通过点、划和停顿组合来表示不同的字母及数字,查找对照表就可以知道表达了什么;
7.亲们趁敌人吃饭时发动进攻;
好用
1
0.因为计算机只能识别0和1
1.汇编语言
2.编译
3.一个面向过程一个面向对象
4.可以
5.源代码不是直接翻译成机器语言,而是先翻译成中间代码,再由解释器对中间代码进行解释运行
6.编译
7.亲们趁敌人吃钱时发动进攻
看答案
让我来对一下答案
感谢分享!
学习