// first off, we need to create a pointer to a directory
//Pointer for DIR
DIR *directorypointer = NULL; // remember, it's good practice to initialise a pointer to NULL!
//directorypointer will refer to the current directory
directorypointer = opendir ("folder");
//if directorypointer does work
if(directorypointer)
{
fprintf(stderr,"Works?");
}
//Creating a Struct of Dirent and pointing it to pent
struct dirent *pent = NULL;
if (directorypointer == NULL) // if pdir wasn't initialised correctly
{
// print an error message and exit the program
fprintf (stderr,"\nERROR! pdir could not be initialised correctly");
} // end if
// while there is still something in the directory to list
while (pent = readdir (directorypointer))
{
// if pent has not been initialised correctly
if (pent == NULL)
{
// print an error message, and exit the program
printf ("\nERROR! pent could not be initialised correctly");
}
// otherwise, it was initialised correctly. let's print it on the console:
fprintf (stderr,"%s\n", pent->d_name);
}
int buffer[100];
int n = NULL;
opendir.read(buffer,n);
}
Here's my error
main.cpp|563|error: request for member 'read' in 'opendir', which is of non-class type 'DIR*(const char*)'|
This error makes sense but I don't know what else has the class type of read that has the same functionality as opendir has.