该程序为<Advanced Programming in the UNIX Environment>英文版, 机械工业出版社出版,第4页中的一个例程,由于没用作者自己定义的.h文件,所以在一些小细节上做了点修改.
在FC4上编译运行通过
源代码如下:
#include<stdio.h>
#include<sys/types.h>
#include<dirent.h>
int main(int argc, char *argv[])
{
DIR *dp;
struct dirent *dirp;
if(argc != 2)
printf("the single argument (a directory name) is required");
if((dp = opendir(argv[1])) == NULL)
printf("can't open %s",argv[1]);
while((dirp = readdir(dp)) != NULL)
printf("%s/n",dirp->d_name);
closedir(dp);
return 0;
}
在FC4上编译运行通过
源代码如下:
#include<stdio.h>
#include<sys/types.h>
#include<dirent.h>
int main(int argc, char *argv[])
{
DIR *dp;
struct dirent *dirp;
if(argc != 2)
printf("the single argument (a directory name) is required");
if((dp = opendir(argv[1])) == NULL)
printf("can't open %s",argv[1]);
while((dirp = readdir(dp)) != NULL)
printf("%s/n",dirp->d_name);
closedir(dp);
return 0;
}