Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Pessoal o código abaixo é um exercício de listas encadeadas, as funções incluir e listar estão compilando normais, mas a função excluir dá erro, alguém pode me dar uma luz :( :unsure: http://forum.imasters.com.br/public/style_emoticons/default/upset.gif :mellow: :wacko:
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <ctype.h>#include <conio.h>typedef struct edificio{ char nome[51]; int hora; int min; struct edificio prox;}edf;//VARIÁVEIS GLOBAISchar nome[51];int hora, min;edf lista;//FUNÇÃO AUXILIARvoid Inserir_Dados (){ printf ("Entre com o nome: "); fflush(stdin); fgets (nome,51,stdin); nome[strlen(nome)-1]='\0';//Remove o /n que a função fgets armazena no buffer. printf ("Entre com a hora: "); fflush(stdin); scanf ("%d",&hora); printf ("Entre com os minutos: "); fflush(stdin); scanf ("%d", &min); printf ("\n");}//FUNÇÃO INCLUIRvoid incluir (){ edf ptr; Inserir_Dados (); ptr = (edf)calloc(1,sizeof(edf)); strcpy(ptr -> nome, nome); ptr -> hora = hora; ptr -> min = min; ptr -> prox= NULL; if (lista == NULL) { lista = ptr; } else { ptr -> prox = lista; lista = ptr; }}//FUNÇÃO CRIA LISTA VAZIAedf vazia(void){ return NULL;}//FUNÇÃO EXCLUIRvoid excluir(){ edf aux1; edf aux2; Inserir_Dados(); aux2 = NULL; aux1 = lista; while (aux1!= NULL) { if((strcmp(aux1-> nome,nome)!=0|| (aux1 -> hora != hora) || (aux1 -> min != min))) { aux2 = aux1; aux1 = aux1 -> prox; } } if (aux2 == NULL) { lista = aux1 -> prox; } else { aux2 -> prox = aux1 -> prox; } free (aux1); printf ("O nome foi excluido \n");}//FUNÇÃO LISTARvoid listar(){ edf aux; aux = lista; while (aux != NULL) { printf ("Nome: %s\n", aux -> nome); printf ("Horas: %d\n", aux -> hora); printf ("Minutos: %d\n\n", aux -> min); aux = aux -> prox; }}//FUNÇÃO PRINCIPALint main(){ char op; lista = vazia(); do{ system("cls"); printf ("(I)ncluir\n"); printf ("(E)xcluir\n"); printf ("(L)istar\n"); printf ("(S)air\n"); printf ("\n"); printf("Digite a opcao: "); op = toupper (getche()); printf ("\n"); switch (op) { case 'I': incluir (); break; case 'E': excluir (); break; case 'L': listar (); break; } system ("PAUSE"); }while(op != 'S'); return (0);}
Carregando comentários...