Perform push and pop operations over stack using string

Push : Push saves value in stack.The values having same data type can be pushed into stack.The value which is pushed at the last is stored at the top most position.

Pop : Push removes value from stack.The top most value is removed first i.e. LIFO policy.After removing a value from stack,the next value becomes the peek value.

In this program,string is pushed and poped from the stack.

// C Language program to implement basic stack operations for a String based Stack

# include < stdio.h >
# include < conio.h >
# define max 5

void main()
{
	//... Create Stack

	char stack[max][80], data[80];
	int top, option, reply;

	// Initialise Stack

	top = -1;
	clrscr();

	do
	{
		printf("\n C Language to implement basic stack operations for String based Stack \n");
		printf("\n 1. Push");
		printf("\n 2. Pop");
		printf("\n 3. Exit");
		printf("\n Select proper option ( 1 / 2 / 3 ) : ");
		scanf("%d", &option);
		switch(option)
		{
			case 1 : // push
				printf("\n Enter a String : ");
				flushall();
				gets(data);
				reply = push(stack,  &top, data);
				if(reply == -1)
					printf("\n Stack is Full \n");
				else
					printf("\n Entered String is Pushed in Stack \n");
				break;
			case 2 : // pop
				reply = pop(stack,  &top, data);
				if(reply == -1)
					printf("\n Stack is Empty \n");
				else
					printf("\n Popped String is : %s", data);
					printf("\n");
				break;
			case 3 : exit(0);
		} // switch
	}while(1);
} // main

int push(char stack[max][80], int *top, char data[80])
{
	if(*top == max -1)
		return(-1);
	else
	{
		*top = *top + 1;
		strcpy(stack[*top], data);
		return(1);
	} // else
} // push

int pop(char stack[max][80], int *top, char data[80])
{
	if(*top == -1)
		return(-1);
	else
	{
		strcpy(data, stack[*top]);
		*top = *top - 1;
		return(1);
	} // else
} // pop