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

王朝other·作者佚名  2008-06-01
窄屏简体版  字體: |||超大  

#include <stdio.h>

#include <dirent.h>

#include <alloc.h>

#include <string.h>

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\n");

exit(1);

}

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

printf("Error opening %s\n",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\n",node->filename);

node=node->next;

}

}

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航