FILELIST.C
Upload User: qq5388545
Upload Date: 2022-07-04
Package Size: 29849k
Code Size: 1k
Category:

GUI Develop

Development Platform:

C/C++

  1. #include <stdio.h>
  2. #include <dirent.h>
  3. #include <alloc.h>
  4. #include <string.h>
  5. #include <stdlib.h>
  6. void main(int argc, char *argv[])
  7.  { 
  8.    DIR *directory_pointer;
  9.    struct dirent *entry;
  10.    struct FileList {
  11.      char filename[64];
  12.      struct FileList *next;
  13.    } start, *node;
  14.    
  15.    
  16.    if ((directory_pointer = opendir(argv[1])) == NULL)
  17.      printf("Error opening %sn", argv[1]);
  18.    else
  19.      {
  20.         start.next = NULL;
  21.         node = &start;
  22.         while (entry = readdir(directory_pointer))
  23.           { 
  24.             node->next = (struct FileList *) malloc(sizeof(struct FileList));           
  25.             if (node == NULL)
  26.              {
  27.                printf("Insufficient memory to store listn");
  28.                exit(1);
  29.              }
  30.             node = node->next;
  31.             strcpy(node->filename, entry);
  32.             node->next = NULL;
  33.           }
  34.         closedir(directory_pointer);
  35.      
  36.      
  37.         node = start.next;
  38.         while (node)
  39.           {
  40.             printf("%sn", node->filename);
  41.             node = node->next;
  42.           }
  43.      }
  44.  }