Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3491198
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:36:29+00:00 2026-05-18T11:36:29+00:00

Our professor required us to check if a word is a palindrome by using

  • 0

Our professor required us to check if a word is a palindrome by using stacks.
Every time I run it, there’s an error: Unhandled Exception. Access violation What am I doing wrong? How can i improve my code? My code is as follows:

 typedef struct stack{
    char name;
    struct stack * next;
}Stack;

void push(Stack**head, char value);
char pop(Stack**head);


int main(){
   char word[11];
   int i=0;
   int lenght = 0; 
   Stack*head = NULL;
   printf("Please type the word: ");
   scanf("%s", word);
   lenght = strlen(word);
   while(word[i]!='\0'){
       push(&head, word[i]);
       i++;
   }
   i = 0;
   while(pop(&head)==word[i]){
       i++;
   }
   if(i==lenght) printf("The word is a palindrome");
   else printf("The word is not a palindrome");
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T11:36:30+00:00Added an answer on May 18, 2026 at 11:36 am

    Your push function should take

    • the address of the stack head (you’ve it correct) and
    • the character that needs to be pushed in (this needs fixing).

    So the method signature becomes:

    void push(Stack**head, char value);
    

    and in the body of the function you add value to the top of stack as:

    temp->name = value;
    

    Also you must always check the return value of malloc.

    Since you are returning the popped value from the function pop it’s return type must not be void, change it to char in both the declaration and the definition as:

    char pop(Stack**head)
    

    There is another logical error:

    To start with you push all the characters of the input into the stack. Next you start popping the characters. There is no terminating condition for your popping. When you’ve popped all the characters (so your stack is empty) the next call to pop will lead to a crash as you’ll be dereferencing a NULL pointer ( *head will be NULL).

    To fix this you pop only the characters you’ve pushed by doing:

    while(i<lenght && pop(&head)==word[i]){
    

    Since the && is short circuited, pop will not be called once you’ve popped all the characters.

    Alternatively (and preferred approach) is to write another function called isEmpty which return true/1 when the stack is empty and use this method before you call the pop method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My professor send out test code to run on our program. However, the test
Our C++ professor mentioned that using the result of operator-> as input into another
For a class assignment, I'm required to write an object to a file. Our
I was given some code by our professor with some things I have never
OK, our professor explained (kinda) this problem, but it still doesn't make much sense.
I've taken 2 OOP C# classes, but now our professor is switching over to
Our professor gave us this assignment, where we have a .txt file with the
We are studying for our CS midterm on Tuesday. Our professor put some study
In my work with my professor I have to ssh into our server and
My professor, (for some unexplained reason) wants to change all input-output files of our

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.