龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 软件开发 > C/C++开发 >

利用链表实现目录内所有文件列表显示

时间:2009-12-22 15:42来源:未知 作者:admin 点击:
分享到:
#include #include #include #include void main(int argc,char *argv[]) { DIR *Directory_pointer; strUCt dirent *entry; struct FileList { char filename[64]; struct FileList *next; }start,*node; if (argc!=2) { printf("Must specify a directory "

#include

  #include

  #include

  #include

void main(int argc,char *argv[])

  {

   DIR *Directory_pointer;

   strUCt dirent *entry;

   struct FileList

   {

   char filename[64];

   struct FileList *next;

   }start,*node;

   if (argc!=2)

   {

   printf("Must specify a directory

");

   exit(1);

   }

   if ((directory_pointer=opendir(argv[1]))==NULL)

   printf("Error opening %s

",argv[1]);

   else

   {

   start.next=NULL;

   node=&start;

   while ((entry=readdir(directory_pointer))!=NULL)

   {

   node->next=(struct FileList *)malloc(sizeof(struct FileList));

   node=node->next;

   strcpy(node->filename,entry->d_name);

   node->next=NULL;

   }

   closedir(directory_pointer);

   node=start.next;

   while(node)

   {

   printf("%s

",node->filename);

   node=node->next;

   }

   }

  }

  

精彩图集

赞助商链接