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 890913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:48:32+00:00 2026-05-15T13:48:32+00:00

I’m trying to complete the Project Euler problem found here. For some reason my

  • 0

I’m trying to complete the Project Euler problem found here. For some reason my function that determines whether or not a given string is a palindrome thinks “989010” is a palindrome. The funny thing is, if I directly enter that string into the palindrome function, it functions correctly. Here’s my code (I’m a newb so sorry for the bad formatting!):

bool palindrome(char pal[]);

int main(){
int i = 0;
int j = 0;
int k = 0;
int numdig = 0;
int numtest = 0;

 for(i = 999; i > 99; i--){
  for(j = 999;j > 99; j--){  //for loops multiply all 3 digit numbers
   k = i * j;
   numtest = k;
   numdig = 0; //this part takes care of determining the number of digits
    while(numtest > 0){
    numdig++;
    numtest /= 10;
    }
   char string[numdig + 1];
   itoa (k,string,10);  //itoa turns an integer into a string w/ null char.
                if( palindrome(string)){
     printf("It is a palindrome: %i\n",k);
     system("pause");
     return 0;
    }
  }
 }
 return 0; 
}

    bool palindrome(char pal[]){
 int half = (sizeof(pal) - 1)/2; //this divides the string in half
 int forward = 0;                 
 int backward = sizeof(pal)-2;   

    while(forward < half && backward > 0){  //compares the charactera in the front 
  if(pal[forward] == pal[backward]){  //to the chars in the back until they
   forward++;                      //meet in the middle
   backward--;
  }
        else{
   return false;
        }
 }
 return true;
}
  • 1 1 Answer
  • 1 View
  • 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-15T13:48:32+00:00Added an answer on May 15, 2026 at 1:48 pm

    The sizeof of the parameter is not the character count of the string pointed to, because the parameter, despite its declaration form, is merely a pointer but not an array. Use strlen instead and notice that it does not include the terminating \0 in its returned value (as opposed to sizeof when applied to a string array).

    The string "989010" looks like a palindrome if you only take the first 3 characters of it, "989". Since sizeof applied to a pointer yields 4 on your machine, it’s only those first three characters that are inspected.

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,

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.