actually I had a problem to reverse my string using stack.. can anyone help me? this is a sample of my code :

#include<iostream>
#include<stdlib.h>
using namespace std;

void push();
void display();
void pop();
struct words
{
char data [20];
struct words *next;
};

words *head;

main()
{
 int i;
 cout<<"enter your alphabet :"<<endl;
 for (i=0; i<4; i++)
 {
 	push();
 }
 display();
 pop();
}

void push()
{
	words *newptr;
	newptr= new words;
	//cout<<"masukkan perkataan";
	cin>>newptr->data;
	newptr->next=NULL;
	newptr->next=head;
	head=newptr;
}

void display()
{
	words *p;
	p=head;
	while (p !=NULL)
	{
	 cout<<p->data;
	 p=p->next;
	}
	cout<<endl;
}

void pop()
{
 words *currentnode;
 currentnode=head;
 if (head !=NULL)
 {
	head=head->next;
 }
else
 {
	cout<< "no data is found";	
 }
 free (currentnode);
}

So what's the problem?

So what's the problem?

the problem is this is not a string..
I just want a string for example :
I just want to entere 'ayam' not
a
y
a
m..
and the result should be 'maya'..
that's what i mean.

the problem is this is not a string..
I just want a string for example :
I just want to entere 'ayam' not
a
y
a
m..
and the result should be 'maya'..
that's what i mean.

What is not a string? What is the definition of this?

Maybe you need to read up on what a string is and how to define it before you continue.

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.