新人求助,C语言S1E2课后作业有一行一直编译不过去
新人求助,S1E2课后作业有一行一直编译不过去,我看了几遍打的代码一样的啊不会发图片 只能把代码复制过来了67 6 C:\Users\Administrator\Desktop\新建文件夹\S1E2作业.c 'handle' undeclared (first use in this function)
67 6 C:\Users\Administrator\Desktop\新建文件夹\S1E2作业.c each undeclared identifier is reported only once for each function it appears in
1
2 #include<io.h>
3 #include<direct.h>
4 #include<stdio.h>
5 #include<stdlib.h>
6 #include<string.h>
7
8 #define MAX 256
9
10 long total;
11
12 int countLines(const char *filename);
13 void finaAllCodes(const char *path);
14 void finaALLFiles(const char *path);
15
16 int countLines(const char *filename)
17 {
18 FILE *fp;
19 int count = 0;
20 int temp;
21
22 if((fp = fopen(filename,"r")) == NULL)
23 {
24 fprintf(stderr,"Can not open the file: %s\n",filename);
25 return 0;
26 }
27
28 while((temp = fgetc(fp)) != EOF)
29 {
30 if(temp == '\n')
31 {
32 count++;
33 }
34 }
35
36 fclose(fp);
37
38 return count;
39 }
40
41 void findAllCodes(const char *path)
42 {
43 struct _finddata_t fa;
44 long handle;
45 char thePath,target;
46
47 strcpy(thePath,path);
48 if((handle = _findfirst(strcat(thePath,"/*.c"),&fa)) != -1L)
49 {
50 do
51 {
52 sprintf(target,"%s%s",path,fa.name);
53 total += countLines(target);
54 }while (_findnext(handle,&fa) == 0);
55 }
56
57 _findclose(handle);
58 }
59
60 void findALLDirs(const char *path)
61 {
62 struct _finddata_t fa;
63 long hanlde;
64 char thePath;
65
66 strcpy(thePath,path);
67 if((handle = _findfirst(strcat(thePath, "/*"), &fa)) == -1L)
68 {
69 fprintf(stderr,"The path %s is wrong!\n",path);
70 return;
71 }
72
73 do
74 {
75 if(!strcmp(fa.name,".")|| !strcmp(fa.name,"."))
76 continue;
77
78 if(fa.attrib == _A_SUBDIR)
79 {
80 sprintf(thePath,"%s/%s",path,fa.name);
81 findAllCodes(thePath);
82 findALLDirs(thePath);
83 }
84 }while (_findnext(handle,&fa) == 0);
85
86 _findclose(handle);
87 }
88
89 int main()
90 {
91 char path=".";
92
93 printf("计算中...\n");
94
95 findAllColes(path);
96 finALLDirs(path);
97
98 printf("目前你总共写了 %ld 行代码!\n\n",total);
99 system("pause");
100
101 return 0;
102 } 95 行,findAllCodes 拼成了 findAllColes
你可以试试直接复制小甲鱼的代码 zltzlt 发表于 2020-8-12 11:05
95 行,findAllCodes 拼成了 findAllColes
你可以试试直接复制小甲鱼的代码
95 行是写错了
67行直接复制小甲鱼的也不能编译,但是复制全部代码可以编译 799495533 发表于 2020-8-12 11:12
95 行是写错了
67行直接复制小甲鱼的也不能编译,但是复制全部代码可以编译
应该是你之前的地方有抄错的 zltzlt 发表于 2020-8-12 11:15
应该是你之前的地方有抄错的
应该是吧 我从新抄一遍试试 好多单词抄错了
#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); // find 你打成 fina 了
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;// handle 你打成 hanlde
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);// Codes 你打成 Coles
findALLDirs(path);// find 少了个 d
printf("目前你总共写了 %ld 行代码!\n\n", total);
system("pause");
return 0;
}
本帖最后由 baige 于 2020-8-12 11:40 编辑
错误的地方已注释,修改好了
看注释了解
13,14,52,63,75,95,96行都有错 问题解决的话,就结贴吧 baige 发表于 2020-8-12 11:35
错误的地方已注释,修改好了
看注释了解
13,14,52,63,75,95,96行都有错
谢谢 baige 发表于 2020-8-12 11:35
错误的地方已注释,修改好了
看注释了解
13,14,52,63,75,95,96行都有错
谢谢大佬
页:
[1]