|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
求大佬指点
这些个是我的错误
16 1 C:\Users\29245\Desktop\芜湖起飞C\第一节课\课后作业\统计.c [Error] expected identifier or '(' before '{' token
27 1 C:\Users\29245\Desktop\芜湖起飞C\第一节课\课后作业\统计.c [Error] stray '\266' in program
27 1 C:\Users\29245\Desktop\芜湖起飞C\第一节课\课后作业\统计.c [Error] stray '\370' in program
C:\Users\29245\Desktop\芜湖起飞C\第一节课\课后作业\统计.c In function 'findAllCodes':
42 1 C:\Users\29245\Desktop\芜湖起飞C\第一节课\课后作业\统计.c [Error] unknown type name 'struct_finddata_t'
47 54 C:\Users\29245\Desktop\芜湖起飞C\第一节课\课后作业\统计.c [Error] 'fa' undeclared (first use in this function)
47 54 C:\Users\29245\Desktop\芜湖起飞C\第一节课\课后作业\统计.c [Note] each undeclared identifier is reported only once for each function it appears in
47 59 C:\Users\29245\Desktop\芜湖起飞C\第一节课\课后作业\统计.c [Error] expected ')' before '!' token
C:\Users\29245\Desktop\芜湖起飞C\第一节课\课后作业\统计.c In function 'findALLDirs':
61 1 C:\Users\29245\Desktop\芜湖起飞C\第一节课\课后作业\统计.c [Error] unknown type name 'struct_finddata_t'
66 52 C:\Users\29245\Desktop\芜湖起飞C\第一节课\课后作业\统计.c [Error] 'fa' undeclared (first use in this function)
80 1 C:\Users\29245\Desktop\芜湖起飞C\第一节课\课后作业\统计.c [Error] stray '\243' in program
80 1 C:\Users\29245\Desktop\芜湖起飞C\第一节课\课后作业\统计.c [Error] stray '\273' in program
81 1 C:\Users\29245\Desktop\芜湖起飞C\第一节课\课后作业\统计.c [Error] expected ';' before 'findALLDirs'
85 1 C:\Users\29245\Desktop\芜湖起飞C\第一节课\课后作业\统计.c [Error] stray '\243' in program
85 1 C:\Users\29245\Desktop\芜湖起飞C\第一节课\课后作业\统计.c [Error] stray '\273' in program
86 1 C:\Users\29245\Desktop\芜湖起飞C\第一节课\课后作业\统计.c [Error] expected ';' before '}' token
C:\Users\29245\Desktop\芜湖起飞C\第一节课\课后作业\统计.c In function 'main':
94 14 C:\Users\29245\Desktop\芜湖起飞C\第一节课\课后作业\统计.c [Error] 'thePath' undeclared (first use in this function)
我的代码如下
#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 *finename);
{
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;
}
而 ((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[MAX], target[MAX];
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[MAX];
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 [MAX] = "." ;
printf("计算中...\n");
findAllCodes(thePath);
findALLDirs (path) ;
printf("目前你总共写了 %1d行代码! \n\n", total);
system("pause");
return 0 ;
}
本帖最后由 isdkz 于 2023-5-4 20:48 编辑
根据你提供的错误信息,以及附带的代码,我为你提供以下修复建议:
1. 第15行:在函数声明中删除分号,并将 finename 更正为 filename 。
int countLines (const char *filename);
改为:int countLines (const char *filename)
2. 第26行以及第79行和第84行:删除非法字符,可能是复制粘贴时产生的。
3. 第41行和第60行: struct_finddata_t 更正为 _finddata_t
4. 第46和第65行: fa 更正为 FA
5. 第46和第65行:使用双等号 == 替换感叹号和等号 !=
6. 第80行:将 findALLDirs 更正为 findALLFiles
7. 第93行:将 thePath 更正为 path
请将代码修改为以下形式:
#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) {
_finddata_t FA;
long handle;
char thePath[MAX], target[MAX];
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 findALLFiles(const char *path) {
_finddata_t FA;
long handle;
char thePath[MAX];
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);
findALLFiles(thePath);
}
} while (_findnext(handle, &FA) == 0);
_findclose(handle);
}
int main() {
char path[MAX] = ".";
printf("计算中...\n");
findAllCodes(path);
findALLFiles(path);
printf("目前你总共写了 %1d行代码! \n\n", total);
system("pause");
return 0;
}
|
|