scandir()
allocates an array of entries.
So you should declare the 2nd paramter like this:
struct dirent ** snapshot = NULL;
And after successfully having called scandir()
you can access its members like this:
printf("%s", snapshot[0]->d_name);
for example.
If the array along with its entries isn't used anymore, 1st free the entries looping over all and calling
free(snapshot[i]);
for each entry and finally do:
free(snapshot);
All this together might look like this:
#include <dirent.h>
int main(void)
{
struct dirent ** namelist = NULL;
int n = scandir(".", &namelist, NULL, alphasort);
if (n < 0)
{
perror("scandir");
}
else
{
while (n--)
{
printf("%s\n", namelist[n]->d_name);
free(namelist[n]);
}
free(namelist);
}
}