0
My code is presenting two errors. As I am learning, I have tried several ways to fix it. Please someone can help me ?
I need to insert a number and a string into my stack. But it’s giving error 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);
}
now I noticed that in your struct hour is a char vector, I went around again and inserted a string, everything worked out the same way... if the error is another try to put an image to see if I can help
– Leila