Program to print names of all files present in a dictionary

Program to print names of all files present in a dictionary


Consider the following code in which we have printed names of all files that are present in the dictionary:

CODE:

# include <stdio. h>

# include <dirent. h>

int main (void)

{

DIR *d;

struct dirent *dir;

d = opendir (“.”);

if (d)

{

while ((dir = readdir (d)) != NULL)

{

printf (“%s\n”, dir -> d_name);

}

closedir (d);

}

return (0);

}

OUTPUT:

File1.txt

File2.txt

File3.txt