//
//
//  Palindrome.cc
//
//      AUTHOR: Russell Lowke
//         T.F: Francis Crick
//  CSCIE-s111: Unit Five, Easy Supp - question 4 [worth 3pts],  7/16/2002
//

#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstring>
#include <cctype>

const int MAXSTR = 40;

bool Palindrome ( char myPalindrome[] )
{
    bool isaPalindrome = true;			// assume is a Palindrome
    char c             = '\n';    		// char holder
    int  theLength     = 0;       		// length of Palindrome
    char fixPalindrome[MAXSTR] = "";	// modified myPalindrome
    
    // trim unwanted characters, such as !, -, etc
    // and convert uppercase to lower
    for (int i = 0; i < strlen(myPalindrome); i++) {
    
        // get next char (lowercase)
        c = tolower(myPalindrome[i]);
       
        if ( isalpha(c) ) {
            fixPalindrome[i] = c;
		}
    }
    
    // store length of Palindrome
    theLength = strlen(fixPalindrome) - 1;
    
    // check if a Palindrome
    for (int i = 0; i <= theLength; i++) {
        if ( fixPalindrome[i] != fixPalindrome[theLength-i] ) {
        	isaPalindrome = false;  // is not a Palindrome
        }
    }
    
    return isaPalindrome;
}


void main()
{
    char mPalindrome[MAXSTR];     // string for Palindrome
    
    // input Palindrome
	cout << "Test a Palindrome: ";

    // read characters from stdin until a newline
    // or MAXSTR characters have been read
    cin.getline(mPalindrome,MAXSTR);
   
	if (Palindrome(mPalindrome)) {
        cout << "Yes, this is a Palindrome" << endl;
	} else {
        cout << "No, this is not a Palindrome" << endl;
	}
	
	exit( 0 );
}
