#include<stdio.h> // for printf() NULL
//#include"error.c"
//#include"apue.h"
#include<dirent.h> //for DIR dirent opendir() readdir()
#include<stdlib.h> //for exit();
int main(int argc,char*argv[])
{
DIR *dir=NULL;
struct dirent * dirp=NULL;
if(argc!=2)
{
printf("the consle order is error\n");
exit(0);
}
if((dir=opendir(argv[1]))==NULL)
{
printf("is the directory name");
exit(0);
}
while((dirp=readdir(dir))!=NULL)
printf("%s\n",dirp->d_name);
exit(0);
}
运行结果