3 * gcc listdir.c -o listdir -Wall -W -Wextra -ansi -pedantic
10 int main(int argc
, char *argv
[])
15 /* Check argument count */
17 fprintf(stderr
, "Usage: %s directory\n", argv
[0]);
22 * Open directory named by argv[1], associate a directory stream
23 * with it and return a pointer to it
25 if ((pdir
= opendir(argv
[1])) == NULL
) {
30 /* Get all directory entries */
31 while((pdent
= readdir(pdir
)) != NULL
)
32 printf("%s\n", pdent
->d_name
);