| 
 | 
 
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册  
 
x
 
新人求助,S1E2课后作业有一行一直编译不过去,我看了几遍打的代码一样的啊  不会发图片 只能把代码复制过来了 
 
67        6        C:\Users\Administrator\Desktop\新建文件夹\S1E2作业.c        [Error] 'handle' undeclared (first use in this function) 
67        6        C:\Users\Administrator\Desktop\新建文件夹\S1E2作业.c        [Note] 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[MAX],target[MAX]; 
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[MAX]; 
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[MAX]="."; 
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        }
 
- #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[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;// handle 你打成 hanlde 
 
 -         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(path);// Codes 你打成 Coles 
 
 -         findALLDirs(path);// find 少了个 d 
 
 -         
 
 -         printf("目前你总共写了 %ld 行代码!\n\n", total);
 
 -         system("pause");
 
 -         
 
 -         return 0;
 
 - }
 
 
  复制代码 
 
 
 |   
 
 
 
 |