int count_files(char *dir)
{
struct dirent *entry;
DIR *dp;
struct stat statbuf;
mode_t modes;
int papka=0, file=0;
if ((dp = opendir(dir)) == NULL)
{
printf("cannot open directory: %s\n", dir);
exit(0);
}
while (entry = readdir(dp))
{
stat(entry -> d_name, &statbuf);
modes = statbuf.st_mode;
if (strcmp(".", entry->d_name) == 0 || strcmp ("..", entry->d_name) == 0){continue;}
printf("%s ", entry->d_name);
if (S_ISDIR(statbuf.st_mode))
{
papka++;
printf ("papka %d \n", papka);
continue;
}
else
{
file++;
printf("file %d \n", file);
continue;
}
}
printf("Papok:%d, faylov:%d", papka, file);
return papka;
}
Функция работает некорректно, считает папки и файлы рандомно, в чем может быть ошибка?