2 gcc listdir.c -o listdir -Wall -W -Wextra -ansi -pedantic */
8 int main(int argc
, char *argv
[])
13 /* check argument count */
15 fprintf(stderr
, "Usage: %s directory\n", argv
[0]);
19 /* open directory named by argv[1], associate a directory stream
20 with it and return a pointer to it
22 if ((pdir
= opendir(argv
[1])) == NULL
) {
27 /* get all directory entries */
28 while((pdent
= readdir(pdir
)) != NULL
)
29 printf("%s\n", pdent
->d_name
);