SHARE
TWEET

Untitled

a guest Jun 24th, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. typedef struct local{
  2.     char *name;
  3.     struct local *next;
  4.  
  5. }t_local;
  6.  
  7. void printlocalsalphabetical(t_local *header_l){
  8.     createlistlocals(*header_l);
  9.     sort_alphabetical(*header_l);
  10.  
  11.     t_local l   = header_l->next;
  12.     while (l){
  13.         puts(l->name);
  14.         l=l->next;
  15.     }
  16.  
  17. }
  18.  
  19. void crialistlocals(t_local *header_l){
  20.     FILE *fp;
  21.     t_local *aux = header_l->next;
  22.     char line[150];
  23.     char *namel;
  24.     fp = fopen("locais.txt","r");
  25.  
  26.     while (!feof(fp)){
  27.         fgets(line, 100, fp);
  28.         namel = strtok(line, '/');
  29.         aux->name = namel;
  30.         aux->next = header_l;
  31.         header_l= aux;
  32.     }
  33.  
  34. }
  35.  
  36. void sort_alphabetical(t_local *header_l){
  37.     int swapped;
  38.     t_local *ptr1;
  39.     t_local *lptr = NULL;
  40.  
  41.  
  42.     if (header_l == NULL)
  43.         return;
  44.  
  45.     do
  46.     {
  47.         swapped = 0;
  48.         ptr1 = header_l;
  49.  
  50.         while (ptr1->next != lptr)
  51.         {
  52.             if (ptr1->name > ptr1->prox->name)
  53.             {
  54.                 swap(ptr1, ptr1->next);
  55.                 swapped = 1;
  56.             }
  57.             ptr1 = ptr1->next;
  58.         }
  59.         lptr = ptr1;
  60.     }
  61.     while (swapped);
  62. }
  63.  
  64. void swap(t_local *a, t_local *b)
  65. {
  66.     char *temp = a->name;
  67.     a->name = b->name;
  68.     b->name = strdup(temp);
  69. }
  70.  
  71.  
  72. t_local *create_headerL(void){
  73.     t_local *list = (t_local*)malloc(sizeof(t_local));
  74.     if (list != NULL)
  75.         list->next = NULL;
  76.  
  77.     return lista;
  78.  
  79. }
  80.  
  81. int main()
  82. {
  83.     t_local *header_l = create_headerL();
  84.     printlocalsalphabetical(*header_l);
  85.     return 0;
  86.  
  87. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top