链表实现文件的列表显示

来源:百度知道 编辑:UC知道 时间:2024/06/06 08:36:52
使用链表来实现将目录下的文件用列表方式显示出来。

怎么做啊?一点思路都没有

#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(n