Skip to content

Commit

Permalink
Create 500.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
MainakRepositor authored Jun 5, 2021
1 parent 9c26142 commit 97b0e14
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions 500.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <stdio.h>
#include <dirent.h>

int main(void)
{
struct dirent *de; // Pointer for directory entry

// opendir() returns a pointer of DIR type.
DIR *dr = opendir(".");

if (dr == NULL) // opendir returns NULL if couldn't open directory
{
printf("Could not open current directory" );
return 0;
}

// Refer http://pubs.opengroup.org/onlinepubs/7990989775/xsh/readdir.html
// for readdir()
while ((de = readdir(dr)) != NULL)
printf("%s\n", de->d_name);

closedir(dr);
return 0;
}

0 comments on commit 97b0e14

Please sign in to comment.