课后作业S1E2
47 strcpy(thePath, path);48 if(handle = _findfirst(strcat(thepath,"/*.c"),&fa)) != -1L)
C语言入门S1E2的课后作业,
47 9 C:\Users\omega\Desktop\FishC\S1E2\未命名4.cpp 'thePath' was not declared in this scope
48 32 C:\Users\omega\Desktop\FishC\S1E2\未命名4.cpp 'thepath' was not declared in this scope
48 54 C:\Users\omega\Desktop\FishC\S1E2\未命名4.cpp expected primary-expression before '!=' token
这哪错了啊??? 发完整代码,你有一些抄错了 本帖最后由 sunrise085 于 2020-8-26 14:03 编辑
47 9 C:\Users\omega\Desktop\FishC\S1E2\未命名4.cpp 'thePath' was not declared in this scope
48 32 C:\Users\omega\Desktop\FishC\S1E2\未命名4.cpp 'thepath' was not declared in this scope
前两个错误是说变量名未定义,猜测可能是你拼写错了。你查一下代码,thePath和thepath 应该都是拼写错了
48 54 C:\Users\omega\Desktop\FishC\S1E2\未命名4.cpp expected primary-expression before '!=' token
这个应该是你多写了半个括号导致的错误
if(handle = _findfirst(strcat(thepath,"/*.c"),&fa)) != -1L)
红色括号去掉应该就没问题了 这是原课后作业47,48行:
strcpy(thePath, path);
if((handle = _findfirst(strcat(thePath, "/*.c"), &fa)) != -1L)
这是作业链接https://fishc.com.cn/forum.php?mod=viewthread&tid=66283&extra=page%3D1%26filter%3Dtypeid%26typeid%3D570
Omega. 发表于 2020-8-26 14:23
这是原课后作业47,48行:
strcpy(thePath, path);
if((handle = _findfirst(strcat(theP ...
你发完整代码 baige 发表于 2020-8-26 14:25
你发完整代码
#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 *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 thePathMAX, targetMAX;
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 finndcAllDirs(const char *path)
{
struct _finddata_t fa;
long handle;
char thePath;
strcpy(thepath,);
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, ".."))
countinue;
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("目前你总共写了%1d行代码!\n\n,total");
system("pause");
return 0;
}
#include<io.h>
#include<direct.h>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define MAX 256 // MAX不是max
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)// thePath不是thepath
{
do {
sprintf(target, "%s/%s", path, fa.name);//这里抄错了
total +=countLines(target);
} while (_findnext(handle, &fa) == 0);
}
_findclose(handle);
}
void findAllDirs(const char *path)// findAllDirs不是finndcAllDirs
{
struct _finddata_t fa;
long handle;
char thePath;
strcpy(thePath,path);// 少了paththePath不是thepath
if((handle = _findfirst(strcat(thePath, "/*"),&fa)) == -1L) // thePath不是thepath
{
fprintf(stderr,"The path %s is wrong!\n",path);
return;
}
do
{
if(!strcmp(fa.name,".")|| !strcmp(fa.name, ".."))//这里抄错了
continue;// continue 不是countinue
if( fa.attrib == _A_SUBDIR)
{
sprintf(thePath,"%s/%s",path,fa.name);// thePath
findAllCodes(thePath);// 同上
findAllDirs(thePath);// 同上
}
} while (_findnext(handle,&fa) == 0);
_findclose(handle);
}
int main()
{
char path = ".";
printf("计算中...\n");
findAllCodes(path);
findAllDirs(path);// findAllDirs不是findALLDirs
printf("目前你总共写了%1d行代码!\n\n,total");
system("pause");
return 0;
}
Omega. 发表于 2020-8-26 14:29
#include
#include
#include
通篇全是错误。
#include <io.h>
#include <direct.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAX 256 // MAX不是max
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)// thePath不是thepath 少了一对括号
{
do
{
sprintf(target, "%s/%s", path, fa.name);//这里抄错了
total += countLines(target);
} while (_findnext(handle, &fa) == 0);
}
_findclose(handle);
}
void findALLDirs(const char *path)// findALLDirs不是finndcAllDirs
{
struct _finddata_t fa;
long handle;
char thePath;
strcpy(thePath,path);// 少了paththePath不是thepath
if((handle = _findfirst(strcat(thePath, "/*"),&fa)) == -1L) // thePath不是thepath
{
fprintf(stderr,"The path %s is wrong!\n",path);
return;
}
do
{
if(!strcmp(fa.name,".")|| !strcmp(fa.name, ".."))//这里抄错了
continue;// continue 不是countinue
if( fa.attrib == _A_SUBDIR)
{
sprintf(thePath,"%s/%s",path,fa.name);// thePath
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;
} baige 发表于 2020-8-26 14:44
谢谢了,第一次抄代码{:10_299:} Omega. 发表于 2020-8-26 15:01
谢谢了,第一次抄代码
看我刚发的,最开始的差个98行没修改 永恒的蓝色梦想 发表于 2020-8-26 14:47
通篇全是错误。
{:10_266:} baige 发表于 2020-8-26 15:02
看我刚发的,最开始的差个98行没修改
OK了
页:
[1]