请教大家一段程序
void ReadDirectories(char *root, int level){
DIR *dir;
//printf("Directory '%s' ", root);
dir = opendir(root);
if(dir) {
struct dirent *dep;
while((dep = readdir(dir)) != NULL) {
int i;
if (strcmp(dep->d_name, ".") && strcmp(dep->d_name, "..")) //这里的if语句有什么作用, strcmp()函数是用来比较两个字符串的,可
{ //可是这里的"."和".."是什么意思呢
for (i = 0; i < level; i++) {
printf(" ");
}
printf("%c %s ", dep->d_type ? 'd' : '-', dep->d_name);
if (dep->d_type) {
char *sub = malloc(strlen(root) + strlen(dep->d_name) + 2); //为什么这里要用到heap,我对heap的了解还很肤浅,请大家帮助
strcpy(sub, root);
strcat(sub, dep->d_name);
strcat(sub, "/");
ReadDirectories(sub, level + 1);
free(sub);
}
}
}
closedir(dir);
}
}