Error in my data structure [PILE]

0

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);
}
    
asked by anonymous 22.03.2018 / 17:00

1 answer

2

Is giving error where? I circled here, used E to stack, typed an hour and a phone number (both integers), then put it to list and they were there.

Here are two messages: unknown escape sequence '\L' on line 70:

printf ("\t\t\Ligacoes");

The latter \ is unknown because \ L is not an escape sequence (like \ n and \ t), so just remove and leave

printf ("\t\tLigacoes");

Another message pointed out was 'typedef' foi ignorada nesta declaração , on line 12:

typedef struct Ligacacao {
        char hora[MAX];
        int numero;
        struct Ligacacao *prox;        
        };

This happened because it is not necessary to use the word typedef in this case, just remove and leave:

struct Ligacacao {
        char hora[MAX];
        int numero;
        struct Ligacacao *prox;        
        };

With these changes, compiled without displaying any warning.

    
24.03.2018 / 18:27