filelist.c

来自「本代码是《C/C++程序员实用大全》的配套代码。网络转载」· C语言 代码 · 共 43 行

C
43
字号
#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 ((directory_pointer = opendir(argv[1])) == NULL)
     printf("Error opening %s\n", argv[1]);
   else
     {
        start.next = NULL;
        node = &start;
        while (entry = readdir(directory_pointer))
          { 
            node->next = (struct FileList *) 
			malloc(sizeof(struct FileList));           
            node = node->next;
            strcpy(node->filename, entry);
            node->next = NULL;
          }

        closedir(directory_pointer);
        node = start.next;
        while (node)
          {
            printf("%s\n", node->filename);
            node = node->next;
          }
     }
 }


⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?