想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
计算中...
目前你总共写了 104 行代码!
已完成
#define _CRT_SECURE_NO_WARINGS
#include <io.h>
#include <direct.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAX 256
long total;
int countLines(const char* filename);
void findALLCodes(const char* patch);
void findALLFiles(const char* patch);
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_s(thePath, path);
if ((handle = _findfirst(strcat(thePath, "/*.c"), &fa)) != -1L)
{
do
{
sprintf_s(target, "%s/%s", path, fa.name);
total += countLines(target);
} while (_findnext(handle, &fa) == 0);
}
_findclose(handle);
}
void findALLFiles(const char* patch)
{
}
void findALLDirs(const char* path)
{
struct _finddata_t fa;
long handle;
char thePath;
sprintf_s(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_s(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;
}
up好,我照着你的这个输入后检查无误但是它提示我fopen和strcat存在危险,在代码第一行输入#define_CRT_SECURE_NO_WARINGS后依然有报错,想问一下这是怎么回事
1
{:5_105:}
查看参考答案
。
.
C:\Users\GH\Pictures\1.jpg
打印出来乱码了
赞同
1
{:5_108:}
我觉得这是很不错的,哈哈
1
鱼C有你更精彩^_^
1
0:CPU是计算机的大脑,虽然它很快,但它并不聪明,它只懂得二进制的-0和1 ,所以如果直接对它下命令,那就是在对牛弹琴,
1:第一代语言,编程语言。
2:编译。引入了大量的助记符来帮助人民编程,然后由汇编编译器将这些助记符转换为机器语言,这个转化的过程称为编译。
3:解释型语言不直接编译成机器语言,而是将源代码转换成中间代码,然后发给解释器,由解释器逐句翻译给CPU来执行。这样好处是可以实现跨平台的功能,缺点结束效率相对要低一些,因为每执行一次都要翻译一次。
4:可以。可移植性高是指源代码不需要做改动或只需稍加改动,就能够在其他机器上编译后正确运行。
5:解释型语言不直接编译成机器语言,而是将源代码转换成中间代码,然后发给解释器,由解释器逐句翻译给CPU来执行。这样好处是可以实现跨平台的功能,缺点结束效率相对要低一些,因为每执行一次都要翻译一次。
6: 查表。
7:不知道(悲)
1
查看答案