各位高手帮看一下啊 这段程序到底有什么问题?
jwwu 2003-10-15 10:04:23 #include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
int dopath(char *path)
{
struct stat statbuf;
struct dirent *dirp;
DIR *dp;
int ret;
char ptr[256];
char ptr1[256];
printf("Ready to analyse path...%s\n",path);
if (stat(path, &statbuf) == -1) {
fprintf(stderr,"path error\n");
return 0;
}
printf("Pass path checking....\n");
if (S_ISDIR(statbuf.st_mode) == 0) {
fprintf(stderr,"not a directory\n");
return 0;
}
memcpy(ptr, path,strlen(path));
if ((dp = opendir(path)) == NULL) {
fprintf(stderr,"read path error\n");
return 0;
}
while ((dirp = readdir(dp)) != NULL) {
if (strcmp(dirp->d_name, ".") == 0 ||
strcmp(dirp->d_name, "..") == 0)
continue;
bzero(ptr1,256);
memcpy(ptr1,ptr,strlen(ptr));
ptr1[strlen(ptr1)] = '/';
ptr1[strlen(ptr1)+1] = '\0';
strcat(ptr1,dirp->d_name);
if ( (ret = dopath(ptr1)) == 0) {
//break
printf("\n\n\n");
}
}
if (closedir(dp) < 0)
fprintf(stderr,"cannot close directory");
return 1;
}
int main()
{
dopath("/home/mm/11");
return 1;
}
一个递归读取目录的函数 为什么读到第2层的时候就读不下去了 特别迷惑
请高手指教