The function top() returns a reference to the top element of the stack.
http://www.cppreference.com/cppstack/top.html
It does not return NULL, but returns a reference to the first object in the stack. Checking for NULL is not a valid thing to do.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
> outfile << "\n\nThe following string was checked for being a palindrome:"
So why don't you print data (your input array) rather than messing with 20+ lines of stack pushing and popping?
If your argument is that it may have unwanted characters, then consider another function to "clean" the line, since you also do that twice as well.
> void main()
Main returns int, always has done.
It's only sloppy books, compilers and tutors which accept void main.
> assert(!outfile.fail());
This causes the program to bail out in debug mode.
Use if/else to check for filename errors and user input errors.
> for(i = 0;(ch = getchar())!='\n'&&i<128;i++)
Is there any chance of buffer overflow with this code?
> while(strcmp(data, flag) != 0)
To save you having to duplicate the "get input" code, try something like this
while ( getUserInput( data ) )
getUserInput is a function which
- prompts for input
- reads a line
- returns the result of the strcmp() result.
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953