0
#include<stdio.h>
#include"push.c"
#include"pop.c"
#include"listadopila.c"
#include"structpila.c"

int main ()
{
    struct pila valor;
    void push();
    int  pop();
    void listado();
    int opcion=0;
    valor.tope= -1;
    int continuar;

    printf ("=====ESTRUCTURA DE PILA=====\n\n");
    do
        {
        printf ("Ingresa tu opcion:\n");
        printf ("1) Para push\n");
        printf ("2) Para pop\n");
        printf ("3) Para mostrar tu pila\n");
        printf ("4) Para salir.\n");
        printf ("\n");

        printf ("Ingresa tu opci%cn\n",163);
        scanf("%d", &opcion);
        switch(opcion)
        {
        case 1:
            push(valor);
            break;
        case 2:
            pop(valor);
            break;
        case 3:
            listado(valor);
            break;
        default:
            printf("Opción no válida.\n");
                    }
            printf("\n¿Desea continuar comprando? Pulse cualquier tecla para si y N para no: ");
            getchar();
            scanf("%d",&continuar); 
            continuar=getchar();
    }

            while(continuar!='n'&&continuar!='N');
        } 

In other file, I define the struct like this:

struct pila
{
int pila[5];
int tope;
}valor;

And my functions are like this:

int pop()
{
    int numero;
    if (valor.tope==- 1)
    {
        printf ("La pila esta vacia.\n");
        return (valor.tope);
    }
    else
    {
        numero=valor.pila[valor.tope];
        printf("El elemento que haz eliminado es= %d", valor.pila[valor.tope]);
        valor.tope=valor.tope -1;
    }
    return(numero);
}

I've tried changing the struct inside and outside the main and to write the functions into the switch case like: pop(valor); but it doesn't work either. Also in the files of each function I've tried to write the function like "int pop(struct pila valor)" but the compiler says I need to add a lenght for valor, the problem is that when I did the code in the same file the compilation finished succesfully, so the problem is when I try to link the struct with the other functions.

Any help?

  • 1
    Conbination of definition `int pop()` and usage `pop(valor);` is bad. You must match arguments between definition and usage. – MikeCAT Mar 05 '17 at 05:15
  • 1
    Object scope, lifetime, identifier hiding, id hiding, are all problems you're code currently suffers from. The very *first* thing I would do is fire the person that told you to `#include` C files in other C files. Then, remove the `valor` definition in your "other file", keeping only the structure declaration. Then, learn about passing parameters to functions, both by value and by address, because you're about to be faced by a slew of unknown identifier errors. [A good book on C](https://stackoverflow.com/questions/562303/the-definitive-c-book-guide-and-list) is warranted. Get one. – WhozCraig Mar 05 '17 at 05:30

0 Answers0