c - Can't find where the segmentation fault is -


i've been programming time now, not much, seems difficult me find segmentation fault is, tried pretty :(. school project , teachers don't on things.

well, here is, code:

#include "funcoes2.h" #include <stdlib.h> #include <stdio.h> #include <string.h>  listaa total_aero = null;  void guarda_voo() {     listaa t; /* struct list of airports */     voo novo_voo;     aeroporto novo_aeroporto1;     aeroporto novo_aeroporto2;       scanf("%s %s %s %d:%d %s %f\n", novo_voo.codigo, novo_voo.aero_partida, novo_voo.aero_chegada, &novo_voo.hora_partida, &novo_voo.minuto_partida, novo_voo.hora_chegada, &novo_voo.preco);      for(t=total_aero; t != null; t = t->prox){         if(!strcmp(t->naero.codigo, novo_voo.aero_partida))             break;     }      if(t == null){         insere_aeroporto(total_aero, novo_aeroporto1); /* adds airport list, think won't reach here when executing */         strcpy(total_aero->naero.codigo, novo_voo.aero_partida);         total_aero->naero.voos_saem++;         strcpy(total_aero->naero.aero_barato, novo_voo.aero_chegada);         strcpy(total_aero->naero.aero_tarde, novo_voo.aero_chegada);         total_aero->naero.preco_barato=novo_voo.preco;         total_aero->naero.hora_tarde=novo_voo.hora_partida;         total_aero->naero.minuto_tarde=novo_voo.minuto_partida;         total_aero->naero.situacao='a';         total_aero->naero.voos = null;         insere_voo((total_aero->naero).voos, novo_voo);         }     else{         t->naero.voos_saem++;         if(novo_voo.preco < (t->naero.preco_barato)){             t->naero.preco_barato=novo_voo.preco;             strcpy(t->naero.aero_barato, novo_voo.aero_chegada);         };         if((t->naero.hora_tarde<novo_voo.hora_partida) || (t->naero.hora_tarde==novo_voo.hora_partida && t->naero.minuto_tarde<novo_voo.minuto_partida)){             (t->naero.hora_tarde=novo_voo.hora_partida);             (t->naero.minuto_tarde=novo_voo.minuto_partida);             strcpy(t->naero.aero_tarde, novo_voo.aero_chegada);         }         insere_voo(t->naero.voos, novo_voo);     }       for(t=total_aero; t != null; t = t->prox){          if(!strcmp(t->naero.codigo, novo_voo.aero_chegada)){             t->naero.voos_chegam++;             return;         }     } 

thanks in advance, if isn't clear, tell me, i'll try explain it

i'll put here .h file:

 typedef struct _st_voo{ char codigo[7]; char aero_partida[4]; char aero_chegada[4]; int hora_partida; int minuto_partida; char hora_chegada[6]; float preco;  }voo;     struct nodev { voo nvoo; struct nodev *prox;  };  typedef struct nodev *listav;     typedef struct _st_aeroporto{ char codigo[4]; int voos_saem; int voos_chegam; char aero_barato[4]; char aero_tarde[4]; float preco_barato; int hora_tarde; int minuto_tarde; char situacao; listav voos;  }aeroporto;    struct nodea { aeroporto naero; struct nodea *prox;  };  typedef struct nodea *listaa;     void guarda_voo();   void info_aeroporto();   void insere_voo(listav x, voo novo_voo);   void remove_voo(listav x, voo cancelado);   void insere_aeroporto(listaa x, aeroporto novo_aero); 

your code entry got messed up. since can't see code or execute it, it's not able find it. have 2 options:

  • right way: learn how debug code using gdb: http://www.gnu.org/software/gdb/
  • dirty way: use printf() print statements console @ different parts of code identify , when segmentation fault occurs.

Comments