My code is displaying two errors. As I'm learning, I've tried several ways to fix it. Can someone please help me?
I need to insert a number and a string in my stack. But you're making a mistake in my structure.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <conio.h>
#define MAX 5
typedef struct Ligacacao {
char hora[MAX];
int numero;
struct Ligacacao *prox;
};
char hora[MAX];
int numero;
Ligacacao *topo; //ERRRRRRO
void dados_ligacao() {
printf ("\nEntre com a hora da chamada: ");
fflush (stdin);
fgets (hora, MAX, stdin);
printf ("Entre com o numero do telefone: ");
fflush (stdin);
scanf ("%d", &numero);
}
void push_ligacao() {
dados_ligacao();
Ligacacao *pnovo=(Ligacacao*)malloc(sizeof(Ligacacao)); //ERRRRRRO
strcpy(pnovo->hora,hora);
pnovo->numero=numero;
pnovo->prox=NULL;
if(topo==NULL)//se a pilha estiver vazia
topo=pnovo; //topo recebe o novo elemento
else{
pnovo->prox=topo;
topo=pnovo;
}
}
void pop_ligacao() {
Ligacacao *aux;
if(topo==NULL){
printf ("\n\nErro, Sem ligacoes.\n\n");
return;
}
else{
aux=topo;
topo=topo->prox;
free(aux);
}
}
void listar_ligacao() {
Ligacacao *aux;
aux=topo;
while(aux!=NULL){
printf ("\t\t\tDados Ligacao\n\n");
printf ("Numero: %d", aux->numero);
aux=aux->prox;
}
}
int main() {
char op;
topo=NULL;
do{
system("cls");
printf ("\t\t\Ligacoes");
printf ("\n\n(E)mpilhar Ligacacao\n");
printf ("(L)istar Estoque Ligacacaos\n");
printf ("(D)esempilhar Ligacacao\n");
printf ("(S)air do Programa\n\n");
printf ("Digite a opcao: ");
op=toupper(getche());
switch(op){
case'E': push_ligacao();
break;
case'L': listar_ligacao();
break;
case'D': pop_ligacao();
break;
case'S': exit(0);
default: printf ("\n\nOpcao invalida, digite novamente.\n\n");
}
system("PAUSE");
}while (op!='S');
return (0);
}