Oi pessoal, tô tentando fazer esse exercício de listas encadeadas, as funções incluir e listar estão normais, mas no meio da execução da função excluir, aparece uma caixa de texto com a seguinte mensagem "o main encontrou um erro e precisa ser fechado", alguém pode me dar uma ajuda. :oops:
#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 GLOBAIS
char nome[51];
int hora, min;
edf *lista;
//FUNÇÃO AUXILIAR
void Inserir_Dados ()
{
printf ("Entre com o nome: ");
fflush(stdin);
fgets (nome,51,stdin);
nome[strlen(nome)-1]='[code]#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 GLOBAIS
char nome[51];
int hora, min;
edf *lista;
//FUNÇÃO AUXILIAR
void 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 INCLUIR
void 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 VAZIA
edf* vazia(void)
{
return NULL;
}
//FUNÇÃO EXCLUIR
void excluir()
{
edf *aux1;
edf *aux2;
Inserir_Dados();
aux2 = NULL;
aux1 = lista;
while ((aux1!= NULL) && ((aux1 -> nome != nome)|| (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 LISTAR
void 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 PRINCIPAL
int 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);
}
printf ("Entre com os minutos: ");
fflush(stdin);
scanf ("%d", &min);
printf ("\n");
}
//FUNÇÃO INCLUIR
void 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 VAZIA
edf* vazia(void)
{
return NULL;
}
//FUNÇÃO EXCLUIR
void excluir()
{
edf *aux1;
edf *aux2;
Inserir_Dados();
aux2 = NULL;
aux1 = lista;
while ((aux1!= NULL) && ((aux1 -> nome != nome)|| (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 LISTAR
void 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 PRINCIPAL
int 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);
}
[/code]
:shock: