title: How can I sort a Linked List with User inputs?
body: <p>I have a project, that generates a Linked List, delete them and show this at the User. Now, I want to sort the list.
  My struct:</p>
  
  <pre><code>typedef struct YugiohCard {
      char Name[100];
      char CardType[20];
      int Level;
      int Rank;
      int PendulumStage;
      int Link;
      int ATK;
      int DEF;
      char Property[20];
      char MonsterType[40];
      char CardType2[30];
      char Description[500];
      struct YugiohCard* pNext;
      struct YugiohCard* pPrev;
  } struYugiohCard;
  </code></pre>
  
  <p>When the User says: "CardType2 Ascending" then the program sort the list by CardType2 and Ascending.</p>
  
  <p>In this case alphematicaly. It is also possible to sort by the other struct contents(Monstertyp, ATK, DEF, etc.). Ascending or Descending.</p>
  
  <p>How can I do it without things from C++?</p>
  
  <p>Sorry for my bad English. I'm not very well at this.</p>
  
  <p><strong><em>Edit:</em></strong>
  Here is my complete Code:</p>
  
  <pre><code>#include "stdio.h"
  #include "stdlib.h"
  #include "string.h"
  #include "time.h"
  
  typedef struct YugiohCard {
      char Name[100];
      char CardType[20];
      int Level;
      int Rank;
      int PendulumStage;
      int Link;
      int ATK;
      int DEF;
      char Property[20];
      char MonsterType[40];
      char CardType2[30];
      char Description[500];
      struct YugiohCard* pNext;
      struct YugiohCard* pPrev;
  } struYugiohCard;
  
  bool OutputList(struYugiohCard* pStart)
  {
      int count = 0;
      struYugiohCard* current = pStart;  // Initialize current 
      while (current != NULL)
      {
          count++;
          current = current-&gt;pNext;
      }
  
      char answer[265];
      int CountetCardsThatWillBeOutputet;
      printf("How many Yugioh cards would you like to spend? 0 means all, 
              otherwise the number counts. Number of elements in list: %i Input:", 
              count);
      fgets(answer, 265, stdin);
      CountetCardsThatWillBeOutputet = atoi(answer);
      int countOutputetCards = 0;
  
      if (CountetCardsThatWillBeOutputet &gt; count)
      {
          printf("Please enter a correct number!");
          system("pause");
          return false;
      }
      else if (CountetCardsThatWillBeOutputet == 0)
      {
          CountetCardsThatWillBeOutputet = count;
      }
  
      system("cls");
      printf("%10s %20s %10s %10s %20s %10s %10s %10s %20s %20s %20s %20s\n", 
      "Name", "CardType", "Level", "Rank", "PendulumStage", "Link", "ATK", 
      "DEF", "Property", "MonsterType", "CardType2", "Description");
      for (struYugiohCard* pOut = pStart; pOut != NULL; pOut = pOut-&gt;pNext)
      {
          printf("%10s %20s %10i %10i %20i %10i %10i %10i %20s %20s %20s 
                  %20s\n", pOut-&gt;Name, pOut-&gt;CardType, pOut-&gt;Level, pOut- 
                  &gt;Rank, pOut-&gt;PendelumStage, pOut-&gt;Link, pOut-&gt;ATK, pOut-&gt;DEF, 
                  pOut-&gt;Property, pOut-&gt;MonsterType, pOut-&gt;CardType2, pOut- 
                  &gt;Description);
          countOutputetCards++;
          if (countOutputetCards == CountetCardsThatWillBeOutputet )
          {
              break;
          }
      }
      system("pause");
  }
  
  void DeleteList(struYugiohCard** head_ref)
  {
      struct YugiohCard* prev = *head_ref;
  
      while (*head_ref)
      {
          *head_ref = (*head_ref)-&gt;pNext;
          free(prev);
          prev = *head_ref;
      }
  }
  
  struYugiohCard* CreateList()
  {
      system("cls");
      char answer[265];
      int countedCards;
      printf("\nHow many Yugioh cards would you like to create? Please enter 
              only enter numbers, otherwise you'll crash.");
      fgets(answer, 265, stdin);
      countedCards = atoi(answer);
  
      struYugiohCard* pFirst = NULL;
  
      for (int i = 0; i &lt; countedCards; i++)
      {
          struYugiohCard* pNew = 
              (struYugiohCard*)malloc(sizeof(struYugiohCard));
          if (pNew == NULL) break;
          pNew-&gt;Name[0] = 'A' + rand() % 26;
          pNew-&gt;Name[1] = '\0';
          pNew-&gt;CardType[0] = 'A' + rand() % 26;
          pNew-&gt;CardType[1] = '\0';
          pNew-&gt;Level = 1 + rand() % 12;
          pNew-&gt;Rank = 1 + rand() % 13;
          pNew-&gt;PendulumStage = 1 + rand() % 12;
          pNew-&gt;Link = 1 + rand() % 8;
          pNew-&gt;ATK = rand() % 10001;
          pNew-&gt;DEF = rand() % 10001;
          pNew-&gt;Property[0] = 'A' + rand() % 26;
          pNew-&gt;Property[1] = '\0';
          pNew-&gt;MonsterType[0] = 'A' + rand() % 26;
          pNew-&gt;MonsterType[1] = '\0';
          pNew-&gt;CardType2[0] = 'A' + rand() % 26;
          pNew-&gt;CardType2[1] = '\0';
          pNew-&gt;Description[0] = 'A' + rand() % 26;
          pNew-&gt;Description[1] = '\0';
          if (pFirst != NULL)
          {
              pNew-&gt;pNext = pFirst;
          }
          else
          {
              pNew-&gt;pNext = NULL;
          }
          pFirst = pNew;
      }
      return pFirst;
  }
  
  int main()
  {   
      struYugiohCard* pStart = NULL;
      printf("\nIMPORTANT: Please maximize the window, otherwise it will not 
              represents everything correctly.");
      do
      {
          system("cls");
          printf("\nDo you want to create a Yugioh card list (YKE) that 
                  Delete Yugioh card list(YKL), a single Yugioh card 
                  delete(EYKL), sort the list(YKS), the Yugioh- 
                  Output card list(YKA) or the program 
                  close(Prsc):");
          char answer[265];
          fgets(answer, 265, stdin);
          if (strcmp(answer, "YKE\n") == 0)
          {
              pStart = CreateList();
          }
          else if (strcmp(answer, "YKS\n") == 0)
          {
              //SortList(pStart);
          }
          else if (strcmp(answer, "EYKL\n") == 0)
          {
              //DeleteOneCard(pStart);
          }
          else if (strcmp(answer, "YKL\n") == 0)
          {
              DeleteList(&amp;pStart);
          }
          else if (strcmp(answer, "YKA\n") == 0)
          {
              OutputList(pStart);
          }
          else if (strcmp(answer, "Prsc\n") == 0)
          {
              return 0;
          }
          else
          {
              printf("Please enter a shortcut!");
          }
      } while (true);
  }
  </code></pre>