how to use push and pop here???

thanks!

#include<stdio.h>
#include<stdlib.h>

void push(char palindrome[20], int *top, int value)
{
    if(*top<=10)
    {
        palindrome[*top]=value;
        *top++;
    }
    else
    {
        printf("Stack is full!!");
        exit(0);
    }

}

int value;
void pop(char palindrome[10], int *top)
{
    if(*top>=0)
    {
        value=palindrome[*top];
        *top=*top-1;
    }
    else
    {
        printf("The stack is empty!!\n");
    }
}

char palindrome[10];
int top = -1;
int value;
int x;

void main()
{
    clrscr();
    printf("Enter word: ");
    scanf("%s",&value);

    for(top=0;palindrome[top]!=x;top++)
    {
    }
    top--;

    for(value=0;palindrome[value]!=x;value++,top--)
    {
        if(palindrome[top]!=palindrome[value])
        x=1;
    }
    if(x==0)
    {
        printf("The word you've entered is a palindrome!!\n");
    }
    else
    {
        printf("The word you've entered is not a palindrome!!\n");
    }
    getch();
}

Perhaps be more specific... what exactly is it that you want to know?

i want to know how to use stacks in this program

You never initialized the value of x. When is the loop supposed to stop? Stopping at the null character '\0' might be a good idea... Also, you can't have both the loop and and function keeping track of top. You can use a while loop to go through the string and push will modify top for you.

Look abby2589 ,

I didn't read all your code but from the general idea of the code i assume that you want to know how to use the stack to check if the word is palindrome or not.

- After you enter the string you will push all of its element from the first character till the end of the string (Using a Pointer ofcourse till the Pointer Reaches NULL).

-Then Pop all the elements from the stack and recieve them in another string.

-And compare the newly created string to the original string that been entered at the first of your program.

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.