1
I’m trying to make a dynamic stack, and for some reason there’s something wrong with the function init
. You’re making the following mistake:
Warning: Conflicting types for 'init'
#include <stdio.h>
#include <stdlib.h>
typedef struct TipoCelular
{
int elemento;
struct TipoCelular *prox;
}elementoPilha;
typedef struct TipoTopo
{
elementoPilha *Topo;
}Pilha;
int main()
{
Pilha *p;
init(p);
if(empty(p))
printf("Pilha vazia\n");
return 0;
}
void init(Pilha *p)
{
p->Topo = NULL;
}
int empty(Pilha *p)
{
if(p->Topo == NULL)
return 1;
return 0;
}
I declared the prototypes, but when compiling gives: . exe stopped working.
– koo
Now that I understand. The
*p
in hismain
is not aPilha
, is only a pointer. Try replacing withPilha p
and when passing it as argument, useinit(&p)
andempty(&p)
. Here’s an example: https://repl.it/@wldomiciano/Example-in-C– wldomiciano
It worked. Thank you!
– koo