Queue item:

typedef struct List{ int key; char name[30]; struct List * next; }tList; 

Function to exchange items

 void elements_swap(tList * elem1,tList * elem2){ tList *n_bufer,*prev1,*prev2,*cp = begin_line; while(cp!= NULL){ if(cp->next == elem1){ prev1 = cp; } if(cp->next == elem2){ prev2 = cp; } cp = cp->next; } prev1->next = elem2; prev2->next = elem1; n_bufer = (tList*)elem1->next; elem1->next = elem2->next; elem2->next = n_bufer; } 

The problem is that comparisons and assignment of pointers of different types occur, i.e. crash occurs at this moment prev2->next = elem1;

Is there a solution other than how to remove typedef ?

  • one
    Something I have a suspicion that you have a mistake in the fact that prev2 , say, zero. Because typedef nothing to do with it. Yes, and add how you begin_line defined (why, for example, you do not pass this value as an argument). - Harry
  • one
    Take a closer look, what will you have if begin_line points to elem1 or elem2 ? - Harry
  • All, thank you very much figured out. - Hardc0re

0