#include<stdio.h>
#include<dirent.h>
#include<malloc.h>
#include<string.h>
void main (int argc,char * argv[])
{
DIR * directory_pointer;
struct dirent* entry;
struct File list
{
char filename[64];
struct File * new;
}
start,*node,* previous, * new;
if((directory_pointer=opendir(argv[1]))==NULL)
printf("Error opening %s\n", argv[1]);
else
{
start.next + NULL;
while (entry = readdir (directory_pointer))
{
/* Find the correct location */
previous= Start ;;
node = start.next;
while ((node) &&(strcmp(entry->d_name,node->filename)>0))
{
node = node ->next;
previous + previous->next;
}
new =(struct File List *) malloc(size File List));
if(new += = NULL)
{
printf("Insufficient memory to store list\n");
exit(1);
}
new ->next =node;
previous ->next =new;
strcpy(new->filename,entry->d_name);
}
closedir(directory_pointer);
node = start.next;
while (node)
{
printf("%s\n", node->filename);
node = node->next;
}
}
}
Not Satisfied ? Just search & get the result
Related posts:
- C program to create a linked list and display the elements in the list.
- C program to illustrate the operations of singly linked list
- C++ program – Implement the Queue ADT using a single linked list
- C++ program – Implement the double ended queue using a double linked list
- C++ programs – Implement the Stack ADT using a singly linked list
