Well basicly the problem is that i have to call the function push while the char that is asked for is not '0' then i have to send the modified "*top" and "*temp" into the function POP so that i can show the values and do the deleting of the charaters that where introduced f3
I think i didnt explained myself verywell i hope you can help me, this is the code i got so far

#include <iostream>
#include <conio.h>

using namespace std;

struct Stack
{
	char letra;
	Stack *next;
};
void push(char n, Stack *top, Stack *temp)
{
		temp=new(Stack);
		temp->letra=n;
		temp->next=top;
		top=temp;// i need to return this values to the main
}
void pop(Stack *top, Stack *temp)//this function should receive the values of top and temp from function push()
{
	int x1;
	temp=top;
	x1=temp->letra;
	cout<<x1;
	top=top->next;
	delete temp;
}
int main()
{
	Stack *start=NULL, *temp=NULL;
	char x;
	do
	{
		cin>>x;
		push(x,start,temp);//i think this function is working
	}
	while(x!='0');
	while(top!=NULL)
	{
		pop(start,temp);//my problem is here f3
	}
	getch();
}

The assignment says that we cant use global declarations for the Stack *start or any Stack structure
which would make this program alot easier f3.
This is my first time using stacks so i know i messed up really bad.
Hope you can help me
Thank you

Look up linked list in google. Try implementing it that way, and
the push and pop should be easy to deal with.

First of all, I think you need to study a little bit more about functions and variable declaration.

First problem is you are declaring your variable "top" in push function and most probably you are expecting that it retains the data when you declare another variable "top" in your pop function(which is not possible). Let me put it in simple words, once push functions is off the stack, all variables declared within the function are eliminated. So top in push is dead once the function returns and it means you can't access the value stored in it in your pop function.

Secondly, I really don't get what you are trying to do as you declare "x1" as integer and you try to assign to it a "Stack" type variable.

So my suggestion before implementing Stack is(which is a little bit hard to do for a beginner, as I am one myself) try to grab more information about Functions, variable declaration, variable scope and variable visibility.

Hope this helps.

Thank you for all the replies problem has been solved

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.