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

include <stdio.h>

include <dirent.h>

include <string.h>

void main(int argc,char *argv[])
{
DIR *directory_pointer;
struct dirent *entry;
char path[80];
struct FileList
{
char filename[64];
struct FileList next;
}start,
node;
puts("Input the directory:");
gets(path);
if ((directory_pointer=opendir(path))==NULL)
printf("Error opening %s ",path);
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;
}
}
}

原文地址:https://www.cnblogs.com/seaw/p/13933448.html