Looking though your code there were several gramatical errors, they were pretty easy to miss since the way the code is layed out its hard to see what belongs where. I added a few comments where i found the missing pieces as I was conforming the code to be more readable.
Also i dont know what compiler your useing but i get a slew of ISO errors compileing it. after I delcared a data type wich is also missing in there.
main.cpp
Code:
# include "palindrome3.h"
# include <iostream.h>
void blankspace(char *s, char *t)
{
while (*s!=NULL)
{
if (*s!=' ') *t=*s;
t++; //missing ; here
s++;
}
*t=NULL; //append NULL to newstring
}
int main(void) //void main() bad
{
const int True=1, False=0;
// create stack object to store string in reverse order.
Stack S;
char palstring[ 80] , blankspacestring[ 80] , c;
int i=0; // string pointer
int ispalindrome=True; //we'll stop if false
// get input
cin. Getline(palstring,80,'\n');
//remove blanks
blankspace(palstring,blankspacestring);// A[],the array;A pointer to A[]
//push character onto stack
i=0;
while(blankedspacestring[i] !=NULL)
{
S.Push(blankspacestring[i] );
i++;
}
//now pop one-by-one comparing with original
i=0;
while (!S.StackEmpty())
{
c=S.Pop();
//get out of loop when first nonmatch
if (c!=blankspacestring[i])
{
isPalindrome=False;
break;
}
// continue till end of string
i++;
}
//operation finished. Printout result
if (ispalindrome) cout<<"\"<<palstring<<"\"<<"is a palindrome<<endl;
else cout<<"\"<<palstring<<"\"<<"is not a palindrome<<endl;
return(0); //missing a return and the final }
}
header
Code:
# include <iostream.h>
# include <stdlib.h>
const int MaxStackSize=50;
class Stack
{
private:
DataType stacklist[ MaxStackSize] ;
int top;
public:
Stack(void); // constructor, initialize top
//modification operations
void Push(const DataType& item);//same as void Push(DataType item)
DataType Pop(void);
void ClearStack(void);
//just copy top item without modifying stack contents
DataType Pick(void) const;
//check stack state
int StackEmpty(void) const;
int StackFull(void) const;
}
// Stack implementation
Stack::Stack(void):top(-1)
{/*void stack function to be filled in later? */}
//Push
void Stack::Push(const DataType& item)
{
//can not push if stack has exceeded its limits
if (top==MaxStackSize-1)
{
cerr<<"Stack overflow"<<endl;
exit(1);
}
// increment top ptr and copy item into list
top++;
stacklist[ top] = item;
}
//pop
DataTaype Stack::Pop(void)
{
DataType temp;
// if stack is empty nothing to pop
if (top==-1)
{
cerr<<"Stack empty"<<endl;
exit(1);
}
//record the top element
temp=stacklist[ top] ;
//decrement top and return the earlier top element
top--;
return temp;
}
//Peek is the same as Pop, except top is not moved
DataType Stack::Peek(void) const
{
}
//Stack Empty
int stack:.StackEmpty(void) const
{
return top==-1; //value is 1 if equal, 0 otherwise
}
// Stack Full
int Satck::StackFull(void) const
{
return top==MaxstackSize-1;
}
//Clear Stack
void Stack::ClearStack(void)
{
top=-1;
}
//some extra chrs down here not attached to function. Also there is no
//define function. while only included once in your project you
//should probley get used to adding it to prevent multiple defnitions
//in larger projects.