1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <sys/types.h>
5 #include <dirent.h>
6
7
8 char Res[147][5]=
9 {
10 "1000","1001","1002","1003","1004",
11 "1100","1101","1102","1103","1104",
12 "1105","1106","1107","1108","1109",
13 "1110","1111","1112","1113","1114",
14 "1116","1117","1119","1120","1121",
15 "1122","1123","1200","1201","1202",
16 "1203","1204","1205","1206","1207",
17 "1208","1303","2001","2002","2003",
18 "2004","2005","2006","2007","2010",
19 "2024","2034","2035","2100","2101",
20 "2200","2201","2300","2301","2302",
21 "2304","2310","2314","2320","2324",
22 "2330","2334","3000","3001","3004",
23 "3010","3014","3015","3020","3030",
24 "3040","3050","3060","3070","3100",
25 "3101","3104","3105","3110","3114",
26 "3115","3150","3160","3161","3200",
27 "3204","3205","3220","4000","4004",
28 "4005","4010","4011","4012","4013",
29 "4014","4015","4016","4017","4018",
30 "4019","4024","4027","4100","4104",
31 "4105","4300","4400","4401","4402",
32 "4410","5000","5004","5005","5010",
33 "5011","5012","5013","5014","5016",
34 "5200","5204","5205","5210","5211",
35 "5212","5213","5214","5216","5300",
36 "5400","5401","5500","5501","5502",
37 "5600","6005","6006","6012","6014",
38 "6015","8000","8004","8100","8200",
39 "8205","8210"
40 };
41
42
43 int main( )
44 {
45 DIR *dp;
46 struct dirent * dirp;
47 FILE *fp;
48 char sString[1024];
49 char Dest[1024];
50 long int stat[147];
51 long int j=0;
52 long int i=0;
53 long int k=0;
54
55
56 for (i=0;i<147;i++)
57 stat[i]=0;
58
59 if ((dp=opendir("HZ_BPo_o801"))==NULL)
60 {
61 printf("The Dirctory is not exit !\n");
62 return -1;
63 }
64
65 while (dirp=readdir(dp)!=NULL)
66 {
67
68 if ((fp=fopen(dirp->d_name,"r"))==NULL)
69 {
70 printf("The File is Not Exit!\n");
71 return -1;
72 }
73 else
74 {
75 while (fgets(sString,1024,fp)!=NULL)
76 {
77 for(i=0;i<147;i++)
78 {
79 if( strncmp(&sString[6],Res[i],4)==0) stat[i]++;
80 }
81 }
82 }
83 fclose(fp);
84 }
85
86 for (i=0;i<147;i++)
87 printf("The number of %s is %d \n",Res[i], stat[i]);
88
89 closedir(dp);
90
91 }
编译能够通过,但是结果不对,出现:The File is not exit!
btw: 我在HZ_BPo_o801下面放了3个文档,先贴出一个文档 test.txt:
A01 0 2300 571642
A01 0 2301 571642
A01 0 2302 571642
A01 0 2310 571642
A01 0 2320 571642
A01 0 2330 571642
A01 0 2300 571642
A01 0 2301 571642
~
请大牛们帮我看看到底哪里出现问题了?
谢谢先!!!!
求助:我编写的程序哪里有问题?