Good evening guys....
i'm newbie in here and in c++...
while i in the middle of pratice in making program...
i try to make a stack that can check whether the string that user input is palindrome or not.
i'm using visual studio 2010 and get autos error

this is the class declaration

class stack
{
public:
	stack();
	~stack();
	void instack();
	void push(char[10]);
	void pop();
	void copy(char[10]);
	void display();
	void palin(char[10]);
	bool more();
	bool isfull();
private:
	int max, check, count;
	char r[10];
	char c[10];
	struct t1;
	typedef t1 *ptr;
	ptr stop;
	struct t1
	{
	char palin[10];
	ptr next;
	};
	ptr head;
};

and here is the code

void stack::pop()
{
	ptr temp;

	if(more())
	{
		temp=stop;
		c[count]=temp->palin[count];
		palin(c);
		stop=stop->next;
		delete temp;
		count++;
	}
}

this one is the palin function

void stack::palin(char c[10])
{
	if(r[count]==c[count])
	{
		check=1;
	}
	else
	{
		check=0;
	}

}

and i got this error

-		c	0x0012ff42 "ÌÌÌÌÌÌÌÌÌÌ"	char [10]
		[0]	-52 'Ì'	char
		[1]	-52 'Ì'	char
		[2]	-52 'Ì'	char
		[3]	-52 'Ì'	char
		[4]	-52 'Ì'	char
		[5]	-52 'Ì'	char
		[6]	-52 'Ì'	char
		[7]	-52 'Ì'	char
		[8]	-52 'Ì'	char
		[9]	-52 'Ì'	char

____________________________________________________________________________________

-		stop	0x00000000 {palin=0x00000000 <Bad Ptr> next=??? }	stack::t1 *
-		palin	0x00000000 <Bad Ptr>	char [10]
		[0]	CXX0030: Error: expression cannot be evaluated	
		[1]	CXX0030: Error: expression cannot be evaluated	
		[2]	CXX0030: Error: expression cannot be evaluated	
		[3]	CXX0030: Error: expression cannot be evaluated	
		[4]	CXX0030: Error: expression cannot be evaluated	
		[5]	CXX0030: Error: expression cannot be evaluated	
		[6]	CXX0030: Error: expression cannot be evaluated	
		[7]	CXX0030: Error: expression cannot be evaluated	
		[8]	CXX0030: Error: expression cannot be evaluated	
		[9]	CXX0030: Error: expression cannot be evaluated	
		next	CXX0030: Error: expression cannot be evaluated

______________________________________________________________________________________

-		temp	0x00000000 {palin=0x00000000 <Bad Ptr> next=??? }	stack::t1 *
+		palin	0x00000000 <Bad Ptr>	char [10]
		next	CXX0030: Error: expression cannot be evaluated

______________________________________________________________________________

-		temp->palin	0x00000000 <Bad Ptr>	char [10]
		[0]	CXX0030: Error: expression cannot be evaluated	
		[1]	CXX0030: Error: expression cannot be evaluated	
		[2]	CXX0030: Error: expression cannot be evaluated	
		[3]	CXX0030: Error: expression cannot be evaluated	
		[4]	CXX0030: Error: expression cannot be evaluated	
		[5]	CXX0030: Error: expression cannot be evaluated	
		[6]	CXX0030: Error: expression cannot be evaluated	
		[7]	CXX0030: Error: expression cannot be evaluated	
		[8]	CXX0030: Error: expression cannot be evaluated	
		[9]	CXX0030: Error: expression cannot be evaluated

really need some help !!
NB: sorry if this is thread is same Repost

How did you implement your 'push' and 'more' functions?

How did you implement your 'push' and 'more' functions?

this the push function

bool stack::push(char x[10])
while(isfull())
{
	{
	ptr newnode;
	newnode= new t1;
	for(int i=0;i<strlen(x);i++)
	{
		newnode->palin[i]=x[i];
	}
	newnode->next=stop;
	stop=newnode;
	}
}

and this is the more function

bool stack::more()
{
	if(max==0)
	{
		return true;
	}
	else
	{
		return false;
	}
}

In your push function:

while(isfull())

It should be

while([B]![/B]isfull())

Silly mistake. Happens to all.

Also, in your more function, you use 'max' variable, but I don't see where you increase or decrease its value anywhere. It will crash because you have never initiated its value.

Even more, in your more() function, you mean to return true if there exists more element or you want to check if it is empty? Current implementation will return true if there is nothing left (isEmpty()), but in your pop() you are using it as if it is isNotEmpty()...

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.