我想请问一下第一课的课后作业要怎么改正自己的错误
undefined reference to `findAllCodes'undefined reference to `findALLCodes'
ld returned 1 exit status
就是编译器出现的这三行字 但我不知道怎么修正
#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 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 ;
} 这是那串代码 本帖最后由 jackz007 于 2020-1-17 00:52 编辑
这是错误信息:
undefined reference to `findALLCodes'
这是问题代码位置
. . . . . .
return count;
}
void findALLcodes(const char *path) // 这个函数名有问题
{
struct _finddata_t fa;
. . . . . .
C / C ++ 语言对标识符字母大小写是敏感的。
所以,这是根本原因:
void findALLcodes(const char *path)
把红色的小写字母 c 它改成大写字母 C,就像下面这样:
void findALLCodes(const char *path)
嗯嗯 谢谢哈 我后面还有个问题就是把findAllCodes(const char*path)写成了findALLCodes(const char*path)
页:
[1]