Hello again guys,

this is the code:

struct nodo {

  char *nom_usuario;   //*user_name
  struct sockaddr_in IP;  
  struct nodo *siguiente; //*next


  struct lista {   //list
    struct nodo *primero;   //*first
    struct nodo *ultimo;    //*last



void ordenar(struct lista* maestra); 
void ordenar(struct lista* maestra){
	struct nodo* aux;
	struct nodo* aux2;
	struct nodo* aux3;

		for(aux=aux2->siguiente; aux!=NULL;aux=aux->siguiente){
		if(strcmp(inet_ntoa(aux->IP.sin_addr),inet_ntoa(aux2->IP.sin_addr))==0)	{
		printf("I'm just checking it's entered the if clause" \n);}


	printf("%s \n",inet_ntoa(aux->IP.sin_addr));


	printf("---------------------- \n");


My situation is as follows:

I have a master list which contains a series of "nodes" (called nodo in the code). The list is empty at first, so one of the things i had to do is to implement the insert operation, which I did, and it works like a charm so far.

The other thing i had to do, is to implement an option which allows us to arrange the nodes of the list according to their IP, having to link together those who have the same IP, for example:

If i have 4 nodes with these IPs

1) => maestra-> primero (first)
4) => maestra->ultimo (last)

the result must be like this:

1) => maestra-> primero (first)
4) => maestra->ultimo (last)

It wasn't stated whether we must put the "smaller" Ips first ( 84.121, 172.16,192....) so that's not a problem.

My problem is that i've tried to implement a solution to that (stated in the code), but it only makes the program enter an endless loop (seems like endless loops love me). So i would be very grateful if any of you guys could give a hint on how to fix this and make it work.

My other problem would be to know where and how to state the new "ultimo".

That for loop in line 40 just shows the list of IPs, i made it just to see whether the process works or not.

Thanks a lot in advance.

6 Years
Discussion Span
Last Post by abhimanipal

The reason why you are getting endless loops is because when you re arrange the pointers, the list becomes circular( Work out your code on a piece of paper if you dont believe me) . Another solution could be to delete the node(totally disconnect it from the list) and then call an insert routine to insert the node at the correct place . I believe this approach will require slightly more code but will be simpler to implement

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.