Problems in code in C List chained

1

I have a problem with a code in C. I'm trying to open a txt file that has movie name, year, actor, ... And I'm putting the movies on a threaded list. The problem is when ordering the movies in the list, I tried to do by the bubble sort method but since the list is too large, when running in Dev the program is running the function infinitely without performing the rest that is in the main (by inefficient ordering) would someone have a clue or help for me to apply in the code and get the list sorted?

Follow the code:

 #include<stdio.h>
 #include<stdlib.h>
 #include<string.h>
 #include<conio.h>
  #define N 10000

 //wt escrita
  //rt leitura

 typedef struct Lista
 {
 char data[N];
 struct Lista *next;
 }Filmes;

 typedef struct ListaDupla 
{
char pessoa[N];
struct ListaDupla *prox;
struct ListaDupla *ant;
}DuplaLista;

  struct Lista* Insert(struct Lista *head,char data[N])
  {
    char aux3[N];
  struct Lista* tmp=((struct Lista*)malloc(sizeof(struct Lista)));
 int aux5;
 strcpy(tmp->data,data);
    tmp->next=NULL;
 if(head==NULL)
 {

    head=tmp;
    return head;
 }else{

struct Lista* aux=head;
struct Lista* aux2=head;
    while(aux->next!=NULL){
        aux=aux->next;
    }

    aux->next=tmp;



    while(aux!=NULL)
    {

        aux2=aux2->next;
        while(aux2!=NULL)
        {
     aux5=strcmp(aux->data,aux2->data);
    if(aux5>0)
    {

        strcpy(aux3,aux->data);
        strcpy(aux->data,aux2->data);
        strcpy(aux2->data,aux3);    
    }
        }
        aux=aux->next;
    }





    return head;
  } 

  // Complete this method
  }

 int main()
 {
 struct Lista* filmes=((struct Lista*)malloc(sizeof(struct Lista)));
 int opcao;
 char aux2[N];
 FILE *arq;
arq=fopen("nomes.txt","rt");
int i,a=0,b,aux;
char linha[600],nome[100];
if(arq==NULL)
{
    printf("Ocorreu um erro!");
    return 1;
}


  while(fgets(linha,700,arq))
  {



char *p=strtok(linha,",");
filmes=Insert(filmes,p);
while(filmes->next!=NULL)

{

printf(" \n Nome:%s",filmes->data);
filmes=filmes->next;
 }











    }



    fclose(arq);

  }
    
asked by anonymous 26.05.2018 / 02:40

0 answers