C语言第一节课
想求助一下大家,在第一节课后作业中,我用codeblocks Windows系统敲的小甲鱼布置的那个一百多行的代码 可是运行的时候总出现这个关于findALLDirs的错误 想知道为什么 求助求助 谢谢大家!! 代码打错了,把你的源代码发出来 临时号 发表于 2022-8-27 21:38代码打错了,把你的源代码发出来
#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 finALLDirs(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("目前你总共写了%ld行代码!\n\n",total);
system("pause");
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 *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)// 这里改为findALLDirs
{
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("目前你总共写了%ld行代码!\n\n",total);
system("pause");
return 0;
} iistan 发表于 2022-8-27 21:48
#include
#include
#include
你代码中确实没有findALLDirs函数啊。
43 21 C:\Users\36218\Desktop\fishc\s1\test.c storage size of 'fa' isn't known
这是为啥呀 iistan 发表于 2022-8-27 21:48
#include
#include
#include
打成finALLDirs了 额外减小 发表于 2022-8-28 00:18
打成finALLDirs了
谢谢 明白了 临时号 发表于 2022-8-27 22:10
看我注释
谢谢 明白了
页:
[1]