0
Hello, I’m starting in the study of data structures and one of the algorithms passed is for data increment in a vector as in a stack (ie, the last incremented is the first to come out) I am in the incrementation part and I am having problems with the performance of my pointer when pointing out the attributes of my stack struct. I have tried to do this without it being a pointer, because then the code seems to "recognize" the attributes, but it has not worked. For now the code is like this.
#include <stdio.h>
#include <stdlib.h>
#define stack_length 100
struct stack {
int top;
int itens[stack_length];
};
void push(struct stack *p, int e ){
if (p.top == (stack_length - 1)){
printf ("\nestouro de pilha");
exit(1);
}
p.itens[++(p.top)] = e;
printf("%d",e);
void main (){
int e = 6;
}
As for the mistakes they are: Error request for member 'top' in something not a structure or a union
Error request for member 'itens' in something not a structure or a union
In rows 11 and 16 respectively:
Line 11: if (p.top == (stack_length - 1)){
(...)
Line 16: p.itens[++(p.top)] = e;
ps: I have not yet properly touched the main function, I filled there only for consciousness awakening...
As p is a pointer to the structure use:
p->top
andp->itens...
or, if you prefer to use the rating with '.':(*p).top
.– anonimo