Ir ao conteúdo
  • Cadastre-se

Estou tendo problemas com código abaixo


Posts recomendados

Estou tendo problemas com código abaixo poderiam me ajudar a ver onde estou errando??? Ta rodando no Dev C++, porém não esta completo.

#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void MenuPrincipal();
void EMPILHAR();
void DESEMPILHAR();
void EXIBIRELEMENTODOTOPO();
void EXIBIRPILHA();
void ESVAZIAR();

#define MAX 3

typedef int telem;

typedef struct {
    telem v[MAX];
    int topo;
    } tpilha;

void criar (tpilha *P);
int vazia (tpilha P);
int cheia (tpilha P);
int tamanho (tpilha P);
int elemtopo (tpilha P, telem *dado);
int push (tpilha *P, telem dado);
int pop (tpilha *P, telem dado);
void imprimir (tpilha *P);

tpilha NUMEROS;
int opcao;

main()
{
    int fim=0;
    criar (&NUMEROS);
    do
    {
        MenuPrincipal();
        switch (opcao)
        {
            case 1:EMPILHAR();
                break;
            case 2:DESEMPILHAR();
                break;/*
            case 3:EXIBIRELEMENTODOTOPO();
                break;
            case 4:EXIBIR PILHA();
                break;
            case 5:ESVAZIAR();
                break;*/
            case 6:fim=1;
                break;
            default: printf("Opcao invalida\n");
                getch();
        }
    }while (!(fim));
    printf("Programa encerrado");
    getch();
}

void MenuPrincipal()
{
    system ("cls");
    printf("EDITOR DE PILHA\n");
    printf("\n1 - EMPILHAR\n");
    printf("\n2 - DESEMPILHAR\n");
    printf("\n3 - EXIBIR ELEMENTO DO TOPO\n");
    printf("\n4 - EXIBIR PILHA\n");
    printf("\n5 - ESVAZIAR\n");
    printf("\n6 - SAIR\n");
    scanf("%d",&opcao);
}

void EMPILHAR()
{
    telem num;
    system("cls");
    printf("EMPILHAR DADOS\n");
    printf("Digite um numero inteiro:");
    scanf("%d",&num);
    if (!(push (&NUMEROS,num)))
             {
                printf("NUMERO MAXIMO DE ELEMENTOS INSERIDOS");
                getch();
                return;
             }
        else
          { 

          }
         
}

void DESEMPILHAR()
    {

    }


int remover (tpilha *P, int pos, telem *dado) {
    int i;
    if ((pos > P->topo) || (pos <=0)) return (0);
    *dado = P->v[pos-1];
    for (i=pos; i<=(P->topo)-1; i++)
        P->v[i-1] = P->v;
    
    (P->topo)--;
    return(1);
    }

void criar (tpilha *p)
{
     p->topo= -1;
}

int  vazia (tpilha P)
{
      return (P.topo == -1);
}

int elemtopo (tpilha P, telem *dado)
{
     if (vazia(P)) return 0;
     *dado =P.v[P.topo];
     return 1;
}

int push (tpilha *p, telem dado)
  { 
           if (p->topo == MAX-1) 
           return 0;
           p->v[++p->topo] = dado;
           return 1;
  }    

int pop (tpilha *p, telem *dado)
{
if (vazia(*p)) return 0;
*dado = p->v[p->topo--];
return 1;
}


 

adicionado 1 minuto depois

Preciso de ajuda nessa implementação.

adicionado 1 minuto depois

preciso de ajuda nessa implementação

Link para o comentário
Compartilhar em outros sites

22 horas atrás, MassakiMsk disse:

@Walquiria Avelar Mourão Você só fez essa parte do código ou tem mais aí? porque assim não vai rodar. chamando uma função que não foi definida.

Onde esta destacado em vermelho estou com dificuldades para terminar pode me ajudar? Só falta isso para estar completo.

 

#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void MenuPrincipal();
void EMPILHAR();
void DESEMPILHAR();
void EXIBIRELEMENTODOTOPO();
void EXIBIRPILHA();
void ESVAZIAR();

#define MAX 3

typedef int telem;

typedef struct {
    telem v[MAX];
    int topo;
    } tpilha;


int menu();
void criar (tpilha *P);
int vazia (tpilha P);
int cheia (tpilha P);
int tamanho (tpilha P);
int elemtopo (tpilha P, telem *dado);
int push (tpilha *P, telem dado);
int pop (tpilha *P, telem dado);
void imprimir (tpilha *P);

tpilha NUMEROS;
int opcao;

main() {
    
    int fim=0;
    criar (&NUMEROS);
    do
    {
        MenuPrincipal();
        switch (opcao)
        {
            case 1:EMPILHAR();
                break;
            case 2:DESEMPILHAR();
                break;
            case 3:EXIBIRELEMENTODOTOPO();
                break;
            case 4:EXIBIR PILHA();
                break;
            case 5:ESVAZIAR();
                break;
            case 0:fim=1;
                break;
            default: printf("Opcao invalida\n");
                getch();
        }
    }while (!(fim));
    printf("Programa encerrado");
    getch();
}

void MenuPrincipal()
{
    system ("cls");
    printf("EDITOR DE PILHA\n");
    printf("\n1 - EMPILHAR\n");
    printf("\n2 - DESEMPILHAR\n");
    printf("\n3 - EXIBIR ELEMENTO DO TOPO\n");
    printf("\n4 - EXIBIR PILHA\n");
    printf("\n5 - ESVAZIAR\n");
    printf("\n6 - SAIR\n");
    scanf("%d",&opcao);
}

void EMPILHAR()
{
    telem num;
    system("cls");
    printf("EMPILHAR DADOS\n");
    printf("Digite um numero inteiro:");
    scanf("%d",&num);
    if (!(push (&NUMEROS,num)))
             {
                printf("NUMERO MAXIMO DE ELEMENTOS INSERIDOS");
                getch();
                return;
             }
        else
          { 

          }
         
}

void DESEMPILHAR()
    {

    }


int remover (tpilha *P, int pos, telem *dado) {
    int i;
    if ((pos > P->topo) || (pos <=0)) return (0);
    *dado = P->v[pos-1];
    for (i=pos; i<=(P->topo)-1; i++)
        P->v[i-1] = P->v;
    
    (P->topo)--;
    return(1);
    }

void criar (tpilha *p)
{
     p->topo= -1;
}

int  vazia (tpilha P)
{
      return (P.topo == -1);
}

int elemtopo (tpilha P, telem *dado)
{
     if (vazia(P)) return 0;
     *dado =P.v[P.topo];
     return 1;
}

int push (tpilha *p, telem dado)
  { 
           if (p->topo == MAX-1) 
           return 0;
           p->v[++p->topo] = dado;
           return 1;
  }    

int pop (tpilha *p, telem *dado)
{
if (vazia(*p)) return 0;
*dado = p->v[p->topo--];
return 1;
}


 

Link para o comentário
Compartilhar em outros sites

void EMPILHAR()
{
    telem num;
    system("cls");
    printf("EMPILHAR DADOS\n");
    printf("Digite um numero inteiro:");
    scanf("%d",&num);
    if (!(push (&NUMEROS,num)))
    {
        printf("NUMERO MAXIMO DE ELEMENTOS INSERIDOS\n");
        getch();
    }
    else
    {
        printf("DADO INSERIDO COM SUCESSO\n");
        getch();
    }
}

void DESEMPILHAR()
{
    telem num;
    system("cls");
    if (pop(&NUMEROS, &num))
    {
        printf("VALOR RETIRADO: %d\n", num);
        getch();
    }
    else
    {
        printf("PILHA VAZIA\n");
        getch();
    }
}

void EXIBIRELEMENTODOTOPO()
{
    telem num;
    system("cls");
    if (elemtopo(NUMEROS, &num))
    {
        printf("VALOR DO TOPO: %d\n", num);
        getch();
    }
    else
    {
        printf("PILHA VAZIA\n");
        getch();
    }
}
void EXIBIRPILHA()
{
    system ("cls");
    int i;
    if(NUMEROS.topo == -1)
        printf("PILHA VAZIA\n");
    else
    {
        printf("PILHA: ");
        for(i=0; i<=NUMEROS.topo; i++)
            printf("%d ", NUMEROS.v[i]);
        printf("\n");
    }
    getch();
}
void ESVAZIAR()
{
    system ("cls");
    NUMEROS.topo = -1;
    printf("PILHA ESVAZIADA COM SUCESSO\n");
    getch();
}

Acredito que seja isso que você quer, mas só uma dúvida. Por que você criou essas funções com letras maiúsculas ao invés de fazer tudo dentro das outras? Por exemplo:

EMPILHAR no push, DESEMPILHAR no pop, EXIBIRELEMENTOTOPO no elementopo?

Qualquer duvida posta ai.

Link para o comentário
Compartilhar em outros sites

Foi feito em sala de aula, pode me informar a outra forma como você mencionou?

adicionado 4 minutos depois

O código não esta rodando, pode me mostrar como fazer tudo dentro das outras? 

Por exemplo:

EMPILHAR no push, DESEMPILHAR no pop, EXIBIRELEMENTOTOPO no elementopo

#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void MenuPrincipal();
void EMPILHAR();
void DESEMPILHAR();
void EXIBIRELEMENTODOTOPO();
void EXIBIRPILHA();
void ESVAZIAR();

#define MAX 3

typedef int telem;

typedef struct {
    telem v[MAX];
    int topo;
    } tpilha;


int menu();
void criar (tpilha *P);
int vazia (tpilha P);
int cheia (tpilha P);
int tamanho (tpilha P);
int elemtopo (tpilha P, telem *dado);
int push (tpilha *P, telem dado);
int pop (tpilha *P, telem dado);
void imprimir (tpilha *P);

tpilha NUMEROS;
int opcao;

main() {
    
    int fim=0;
    criar (&NUMEROS);
    do
    {
        MenuPrincipal();
        switch (opcao)
        {
            case 1:EMPILHAR();
                break;
            case 2:DESEMPILHAR();
                break;
            case 3:EXIBIRELEMENTODOTOPO();
                break;
            case 4:EXIBIRPILHA();
                break;
            case 5:ESVAZIAR();
                break;
            case 0:fim=1;
                break;
            default: printf("Opcao invalida\n");
                getch();
        }
    }while (!(fim));
    printf("Programa encerrado");
    getch();
}

void MenuPrincipal()
{
    system ("cls");
    printf("EDITOR DE PILHA\n");
    printf("\n1 - EMPILHAR\n");
    printf("\n2 - DESEMPILHAR\n");
    printf("\n3 - EXIBIR ELEMENTO DO TOPO\n");
    printf("\n4 - EXIBIR PILHA\n");
    printf("\n5 - ESVAZIAR\n");
    printf("\n6 - SAIR\n");
    scanf("%d",&opcao);
}

void EMPILHAR()
{
    telem num;
    system("cls");
    printf("EMPILHAR DADOS\n");
    printf("Digite um numero inteiro:");
    scanf("%d",&num);
    if (!(push (&NUMEROS,num)))
             {
                printf("NUMERO MAXIMO DE ELEMENTOS INSERIDOS");
                getch();
                return;
             }
        else
          { 
        printf("DADO INSERIDO COM SUCESSO\n");
        getch();
          }
         
}

void DESEMPILHAR()
    {
    telem num;
    system("cls");
    if (pop(&NUMEROS, &num))
    {
        printf("VALOR RETIRADO: %d\n", num);
        getch();
    }
    else
    {
        printf("PILHA VAZIA\n");
        getch();
    }
}

void EXIBIRELEMENTODOTOPO()
{
    telem num;
    system("cls");
    if (elemtopo(NUMEROS, &num))
    {
        printf("VALOR DO TOPO: %d\n", num);
        getch();
    }
    else
    {
        printf("PILHA VAZIA\n");
        getch();
    }
}

void EXIBIRPILHA()
{
    system ("cls");
    int i;
    if(NUMEROS.topo == -1)
        printf("PILHA VAZIA\n");
    else
    {
        printf("PILHA: ");
        for(i=0; i<=NUMEROS.topo; i++)
            printf("%d ", NUMEROS.v);
        printf("\n");
    }
    getch();
}

void ESVAZIAR()
{
    system ("cls");
    NUMEROS.topo = -1;
    printf("PILHA ESVAZIADA COM SUCESSO\n");
    getch();
}

int remover (tpilha *P, int pos, telem *dado) {
    int i;
    if ((pos > P->topo) || (pos <=0)) return (0);
    *dado = P->v[pos-1];
    for (i=pos; i<=(P->topo)-1; i++)
        P->v[i-1] = P->v;
    
    (P->topo)--;
    return(1);
    }

void criar (tpilha *p)
{
     p->topo= -1;
}

int  vazia (tpilha P)
{
      return (P.topo == -1);
}

int elemtopo (tpilha P, telem *dado)
{
     if (vazia(P)) return 0;
     *dado =P.v[P.topo];
     return 1;
}

int push (tpilha *p, telem dado)
  { 
           if (p->topo == MAX-1) 
           return 0;
           p->v[++p->topo] = dado;
           return 1;
  }    

int pop (tpilha *p, telem *dado)
{
if (vazia(*p)) return 0;
*dado = p->v[p->topo--];
return 1;
}
  

 

Link para o comentário
Compartilhar em outros sites

Visitante
Este tópico está impedido de receber novas respostas.

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...