Guest User

Untitled

a guest
May 26th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<string.h>
  4. #include<conio.h>
  5. #define N 10000
  6.  
  7. typedef struct Lista
  8. {
  9. char data[N];
  10. struct Lista *next;
  11. }Filmes;
  12.  
  13. typedef struct ListaDupla
  14. {
  15. char pessoa[N];
  16. struct ListaDupla *prox;
  17. struct ListaDupla *ant;
  18. }DuplaLista;
  19.  
  20. struct Lista* Insert(struct Lista *head,char data[N])
  21. {
  22. char aux3[N];
  23. struct Lista* tmp=((struct Lista*)malloc(sizeof(struct Lista)));
  24. int aux5;
  25. strcpy(tmp->data,data);
  26. tmp->next=NULL;
  27. if(head==NULL)
  28. {
  29. head=tmp;
  30. return head;
  31. }else
  32. {
  33. struct Lista* aux=head;
  34. struct Lista* aux2=head;
  35. while(aux->next!=NULL){
  36. aux=aux->next;
  37. }
  38.  
  39. aux->next=tmp;
  40.  
  41. while(aux!=NULL)
  42. {
  43. aux2=aux2->next;
  44. while(aux2!=NULL)
  45. {
  46. aux5=strcmp(aux->data,aux2->data);
  47. if(aux5>0)
  48. {
  49. strcpy(aux3,aux->data);
  50. strcpy(aux->data,aux2->data);
  51. strcpy(aux2->data,aux3);
  52. }
  53. }
  54. aux=aux->next;
  55. }
  56.  
  57. return head;
  58. }
  59.  
  60. // Complete this method
  61. }
  62.  
  63. int main()
  64. {
  65. struct Lista* filmes=((struct Lista*)malloc(sizeof(struct Lista)));
  66. int opcao;
  67. char aux2[N];
  68. FILE *arq;
  69. arq=fopen("nomes.txt","rt");
  70. int i,a=0,b,aux;
  71. char linha[600],nome[100];
  72. if(arq==NULL)
  73. {
  74. printf("Ocorreu um erro!");
  75. return 1;
  76. }
  77. while(fgets(linha,700,arq))
  78. {
  79. char *p=strtok(linha,",");
  80. filmes=Insert(filmes,p);
  81. while(filmes->next!=NULL)
  82. {
  83. printf(" n Nome:%s",filmes->data);
  84. filmes=filmes->next;
  85. }
  86. }
  87. fclose(arq);
  88. }
Add Comment
Please, Sign In to add comment