不知道哪里有问题,第一天大佬救命
#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 findA11Codes(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;
longhandle;
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);
findA11Codes(thePath);
findALLDirs(thePath);
}
}while (_findnext(handle, &fa) == 0);
_findclose(handle);
}
int main()
{
char path = ".";
printf("计算中...\n" );
findA11Codes(path);
findALLDirs(path);
printf("目前你总共写了 %1d 行代码! \n\n", total);
system("pause");
return 0;
} 认真一点,因为一个字符也不能错
findA11Codes
你能分清楚数字1和字母l吗?
与此类似的 0 O o ! 1 i l ` ' , .
这些都是不同的字符
代码中肯定还有很多这类写错字符的情况
你说你不认真写错了字符能怎么办?
要真的想学编程,那就请认真一点吧
一个字符也不能错,你这错了几个字符了,至少也两个了,这是至少
就在此时,我又发现了一个
printf("目前你总共写了 %1d 行代码! \n\n", total);
已经至少错了3个字符了,错一个都不行,你已经错了至少3个了,程序当然是不能运行了
我就不一个一个给你数了,错的肯定不止这3个字符
自己认真一点,一个字符一个字符的检查吧
顺便数一数错了多少个字符
如果第1次错了100个字符,第2次错了90个字符
这就是进步,有进步就是好的,慢慢来吧
请记住, 要真的想学编程,那就请认真一点吧 我简单的看了一下,好像是错了11个字符
删除了一些不影响错误的字符,一共错了12个字符
页:
[1]