C program for sorting a Linked List

C program for sorting a Linked List.

#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;
		}
	}
}
Editorial Team
Editorial Team

We are a group of young techies trying to provide the best study material for all Electronic and Computer science students. We are publishing Microcontroller projects, Basic Electronics, Digital Electronics, Computer projects and also c/c++, java programs.

Leave a Reply

Your email address will not be published. Required fields are marked *

Get the latest updates on your inbox

Be the first to receive the latest updates from Codesdoc by signing up to our email subscription.

    StudentProjects.in