Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 11th, 2012  |  syntax: None  |  size: 3.55 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include "genericLL.h"
  2. #include "genericHash.h"
  3. #include "lugar.h"
  4. #include "files.h"
  5. #include <stdio.h>
  6.  
  7. int main() {
  8.        
  9.         int i=0;
  10.        
  11.         Hash* hash_lugares;
  12.         FILE *fp, *fpt;
  13.        
  14.         Lista* lista_aux = (Lista *) malloc(sizeof(Lista));
  15.         Nodo* nodo_aux = (Nodo *) malloc(sizeof(Nodo));
  16.         Lugar* lugar_aux = (Lugar *) malloc(sizeof(Lugar));
  17.        
  18.         hash_lugares = init_hash();
  19.        
  20.         if ((fp = fopen("teste.txt", "r")) == NULL)
  21.                 fprintf(stderr, "Cannot open %s\n", "teste.txt");
  22.        
  23.        
  24.         while(!feof(fp)){
  25.        
  26.                 carrega_lugares(fp,hash_lugares);
  27.         }
  28.        
  29.        
  30.         printf("Carreguei a hash\n");
  31.         getchar();
  32.         //fclose(fp);
  33.        
  34.         for(i=0; i<HASH_SIZE; i++){
  35.                
  36.                 lista_aux = (*hash_lugares)[i];
  37.                 if(lista_aux != NULL)
  38.                 {nodo_aux = lista_aux -> root;
  39.                
  40.                 lugar_aux = nodo_aux -> dados;
  41.                 }
  42.                
  43.                 printf("-----------> iteração i:%d\n\n",i);
  44.                 //getchar();
  45.                
  46.                 if(lista_aux == NULL ) printf("posição i = NULL\n\n",i);
  47.                
  48.                 if(lista_aux!=NULL){
  49.                
  50.                 while(nodo_aux != NULL){
  51.                         printf("%d:",lugar_aux -> codigo);
  52.                         printf("%s:",lugar_aux -> nome);
  53.                         printf("%d.",lugar_aux -> latitude.graus);
  54.                         printf("%d:",lugar_aux -> latitude.minutos);
  55.                         printf("%d.",lugar_aux -> longitude.graus);
  56.                         printf("%d:",lugar_aux -> longitude.minutos);
  57.                         printf("%d\n",lugar_aux -> pontos_checkin);
  58.                        
  59.                         nodo_aux = nodo_aux -> proximo;
  60.                         if(nodo_aux != NULL) lugar_aux = nodo_aux -> dados;
  61.                        
  62.                 }
  63.                 }
  64.        
  65.         }
  66.        
  67.         free(lista_aux);
  68.         free(nodo_aux);
  69.         free(lugar_aux);
  70.  
  71.  
  72.         if ((fpt = fopen("coord.txt", "w")) == NULL)
  73.                 fprintf(stderr, "Cannot open %s\n", "coord.txt");
  74.  
  75. /*
  76.         Lugar* lugarteste1 = (Lugar*) malloc(sizeof(Lugar));
  77.         Lugar* lugarteste2 = (Lugar*) malloc(sizeof(Lugar));
  78.        
  79.         lugarteste2->codigo = 1834;
  80.         strcpy(lugarteste2->nome, "CCISEL - Centro de Cálculo do ISEL");
  81.         lugarteste2->latitude.graus = 38;
  82.         lugarteste2->latitude.minutos = 45;
  83.         lugarteste2->longitude.graus = -9;
  84.         lugarteste2->longitude.minutos = 6;
  85.         lugarteste2->pontos_checkin = 10;
  86.         strcpy(lugarteste2->mayorship.nickname, "Offman");
  87.         lugarteste2->mayorship.pontos = 40;
  88.         lugarteste2->proximo = NULL;
  89.        
  90.        
  91.         lugarteste1->codigo = 3;
  92.         strcpy(lugarteste1->nome, "Rendufas do Meio");
  93.         lugarteste1->latitude.graus = 39;
  94.         lugarteste1->latitude.minutos = 33;
  95.         lugarteste1->longitude.graus = -8;
  96.         lugarteste1->longitude.minutos = 31;
  97.         lugarteste1->pontos_checkin = 10;
  98.         strcpy(lugarteste1->mayorship.nickname, "Offman");
  99.         lugarteste1->mayorship.pontos = 40;
  100.         lugarteste1->proximo = lugarteste2;
  101. */        
  102.        
  103.         printf("bamo guardar");
  104.         getchar();
  105.  
  106.         guardar_lugares(fpt, hash_lugares);
  107.        
  108.         fclose(fp);
  109.         fclose(fpt);
  110.        
  111.         return 1;
  112. }