So, I wanted to create a stack as follows:
#include <stdio.h>
#include <stdlib.h>
typedef struct Node{
int data;
struct node *link;
}node;
typedef struct Stack{
struct Node *topnode;
int count;
}stack;
void push(int data, stack *ourstack){
node newnode;
newnode.data = data;
ourstack.topnode = &newnode;
}
int main()
{
stack mystack;
push(1,mystack);
printf("%d",(mystack.(*topnode).data));
}
but I do get errors. I am a bit confused here. Inside the push() function, in the last line, I tried various ways of implementing it right but I failed each time. Now, my thinking is, ourstack is a pointer pointing to a struct Stack. And the topnode is also a pointer inside a structure of a stack which points to another node structure. So, should not (*ourstack).(*topnode) = newnode or ourstack.topnode = &newnode work? Why?
ourstack.topnode = &newnode@JohnZwinckstruct Node->struct node,ourstack.topnode->ourstack->topnode,push(1, mystack);->push(1, &mystack);,(mystack.(*topnode).data)->mystack.topnode->dataand a few more problems.