-1
I am typing the code that is presented in a book and compiling gradually. Mistakes happen where they are "//???????????".
Another detail, in the statement of the structure, where we see *Stack, in this structure, by being declared as pointer, I would be passing the address of the variables within the structure, correct?
#include<stdio.h>        
#include<stdlib.h>
typedef char Itemp;      
typedef struct pilha{   
    int max;   
    int topo;  
    Itemp *item;
    
} *Pilha;   
Pilha pilha(int m){  
    Pilha P=malloc(sizeof(struct pilha));//????????  
    P->max=m;  
    P->topo=-1;
    P->item=malloc(m*sizeof(Itemp));//???????????   
    return P;    
}
int vaziap(Pilha P){        
    if(P->topo==-1) return 1;        
    else return 0;        
}
int cheiap(Pilha P){    
    if(P->topo==P->max-1) return 1;    
    else return 0;   
}
void empilha(Itemp x,Pilha P){         
    if(cheiap(P)) puts("pilha cheia!"); abort();        
    P->topo++;        
    P->item[P->topo]=x;        
    
}
						
It would be nice to inform the errors that appear on the screen.
– Heitor Scalabrini
I believe the variable
P, of type Pliha, must be a global variable and not local to the functionpilha. Study the scope of variables.– anonimo
I guess instead of
if(cheiap(P)) puts("pilha cheia!"); abort();, what you wanted wasif(cheiap(P)) { puts("pilha cheia!"); abort(); }- The{and the}are very important here.– Victor Stafusa