Skip to content

Instantly share code, notes, and snippets.

@uhziel
Created September 25, 2011 16:23
Show Gist options
  • Save uhziel/1240790 to your computer and use it in GitHub Desktop.
Save uhziel/1240790 to your computer and use it in GitHub Desktop.
apue.2e.fig1.3.c
#include "apue.h"
#include <dirent.h>
int main(int argc, char *argv[])
{
DIR *dp;
struct dirent *dirp;
if (argc != 2)
{
err_quit("usage: ls dir_name");
}
if ((dp = opendir(argv[1])) == NULL)
{
err_sys("can't open %s", argv[1]);
}
while ((dirp = readdir(dp)) != NULL)
{
printf("%s\n", dirp->d_name);
}
closedir(dp);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment