Good night;

can you see this function ;
its true


but the only error is :
missing ';' before 'return'
missing ';' before '}'
missing ';' before '}'
missing ';' before '{'
missing function header (old-style formal list?)

but there is no ; missing , i checked it twice

this is my function (for checking if word is Palindrome-madam-. or not by push half of the word in a stack and then compare it with the other half of the word) :

template <class Type>
int isPalindrome (Type * word)
{ stackType <Type> mystack;
int i=0,count=0;
while(word[i]!=NULL)
{
count++;
i++;
}
int half=count/2;
for(int j=0;j<half;j++)
{ mystack.push(word[j]);}
 
if(count%2==1)//............... Odd No.
{
j=j+2;
while(word[j]!=NULL)
{
if(word[j]==mystack.top())
{mystack.pop();
j++;
}
else 
{ return 0;}
}
}
else //.................Even No.;
{ j++;
while(word[j]!=NULL)
{ if (word[j]==mystack.top())
{ mystack.pop();
j++;
}
else
{ return 0 ;}
}
}
}

return 1;
}

If you actually formatted your code intelligently, this error would be obvious. Here's the same code with better formatting. I've pointed out the error in red:

template <class Type>
int isPalindrome (Type * word)
{ 
  stackType <Type> mystack;
  int i=0,count=0;
  while(word[i]!=NULL)
  {
    count++;
    i++;
  }
  int half=count/2;
  for(int j=0;j<half;j++)
  { 
    mystack.push(word[j]);
  }

  if(count%2==1)//............... Odd No.
  {
    j=j+2;
    while(word[j]!=NULL)
    {
      if(word[j]==mystack.top())
      {
        mystack.pop();
        j++;
      }
      else
      { 
        return 0;
      }
    }
  }
  else //.................Even No.;
  { 
    j++;
    while(word[j]!=NULL)
    { 
      if (word[j]==mystack.top())
      { 
        mystack.pop();
        j++;
      }
      else
      { 
        return 0 ;
      }
    }
  }
}

return 1;
}

thanks for your qiuck reply

how did you get it quickly !

:)

Now , there is another problem in the function itself
it does not work as supposed to be . :-/

>how did you get it quickly !
I happened to be active when you posted.

>it does not work as supposed to be
Your code is too complicated. Remove anything that's redundant, and be sure to walk through the execution on paper so that you know all of your variables have the right values. Then step through the code and verify that your paper run matches the actual execution. You several problems, try to figure out what I changed and why I changed it:

int isPalindrome ( const char *word )
{
  std::stack<const char> mystack;
  int count = 0;

  while ( word[count] != '\0' )
    ++count;

  int half = count / 2;
  int j;

  for ( j = 0; j < half; j++ )
    mystack.push ( word[j] );

  if ( count % 2 != 0 )
    ++j;

  while ( word[j] != '\0' ) {
    if ( word[j] == mystack.top() ) {
      mystack.pop();
      j++;
    }
    else
      return 0;
  }

  return 1;
}
int isPalindrome ( const char *word )
{
  std::stack<const char> mystack;
  int count = 0;

  while ( word[count] != '\0' )
    ++count;

  int half = count / 2;
  int j;
...
}

Any reason for not using strlen ? :-)

>Any reason for not using strlen ? :-)
None I can think of, but I didn't want to cause more confusion than necessary.

for checking if word is Palindrome-madam-. or not by push half of the word in a stack and then compare it with the other half of the word)

why do you need a stack at all?

template< typename CHAR_TYPE>
inline bool is_palindrome( const CHAR_TYPE* begin )
{
  const CHAR_TYPE* end = begin ;
  while( *end ) ++end ;
  while( begin < end )
    if( *begin++ != *--end ) return false ;
  return true ;
}

strlen is not used as the original function was polymorphic on the charater type.

>how did you get it quickly !
I happened to be active when you posted.

>it does not work as supposed to be
Your code is too complicated. Remove anything that's redundant, and be sure to walk through the execution on paper so that you know all of your variables have the right values. Then step through the code and verify that your paper run matches the actual execution. You several problems, try to figure out what I changed and why I changed it:

int isPalindrome ( const char *word )
{
  std::stack<const char> mystack;
  int count = 0;
 
  while ( word[count] != '\0' )
    ++count;
 
  int half = count / 2;
  int j;
 
  for ( j = 0; j < half; j++ )
    mystack.push ( word[j] );
 
  if ( count % 2 != 0 )
    ++j;
 
  while ( word[j] != '\0' ) {
    if ( word[j] == mystack.top() ) {
      mystack.pop();
      j++;
    }
    else
      return 0;
  }
 
  return 1;
}

yahh , my code is too complicated with comparing with your code

Now it become easier to understsnd.

But i want to know what does

std::

mean ?

BTW 7 error still there !

error C2039: 'stackType' : is not a member of 'std'
error C2143: syntax error : missing ';' before '<'
error C2143: syntax error : missing ';' before '<'
'mystack' : undeclared identifier
left of '.push' must have class/struct/union type
left of '.top' must have class/struct/union type
left of '.pop' must have class/struct/union type

Any reason for not using strlen ? :-)

i know this function but remember it just after posting the code

>yahh , my code is too complicated with comparing with your code
You can create good code by taking mediocre code and chipping away at it until nothing else can be removed. And of course, great code is designed to be elegant from the start. ;)

>But i want to know what does std:: mean ?
No doubt you have using namespace std; somewhere in your code. If you take that out, you have to prefix each name that's in the std namespace with std::.

>error C2039: 'stackType' : is not a member of 'std'
I didn't have your stackType, so I used the standard stack template. It's in the std namespace, but your custom stack type isn't, so you need to remove the std:: prefix.

>error C2143: syntax error : missing ';' before '<'
>error C2143: syntax error : missing ';' before '<'
>'mystack' : undeclared identifier
>left of '.push' must have class/struct/union type
>left of '.top' must have class/struct/union type
>left of '.pop' must have class/struct/union type
These are waterfall errors that stem from the first error. If you correct it, they'll disappear.

You can check ending & starting of function's bracket by simply pressing the key (Ctrl + e ).In this way u can track your problem.

>You can check ending & starting of function's bracket by simply pressing the key (Ctrl + e ).
It sounds very much like you're describing a feature of your favorite text editor and not a universal capability. :icon_rolleyes:

std::stack<const char> mystack;

after removing red words from the above decleration and also from the prototype , all errors disapear .


thanks alot erery 1 :icon_surprised:

This question has already been answered. Start a new discussion instead.