You have a lot of errors in that program syntactic and logical. Here's the fixed program :-)
Code:
#include <iostream.h>
#include <string.h>
int main()
{
int length;
int arr1=0;
typedef char string[30];
typedef char string2[30];
string word[10];
string2 invWord[10];
cout<<"Enter word"<<endl;
cin>>word[arr1];
while (stricmp(word[arr1], "Quit")!= 0)
{
length=strlen(word[arr1]);
for (int j=0, i=length-1; j<length; j++, i--)
{
invWord[arr1][j]=word[arr1][i];
}
invWord[arr1][length] = '\0';
if (strcmp(word[arr1], invWord[arr1]) == 0)
cout<<"Palindrome"<<endl;
cout<<"Enter word"<<endl;
cin>>word[++arr1];
}
return 0;
}
But you can do a lot better, here's my stab at it :-)
Code:
#include <functional>
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
class good_char: public unary_function<char, bool> {
const string good;
public:
good_char()
: good("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
{}
bool operator()(const char c) const
{
if (good.find(c) != string::npos)
{
return true;
}
return false;
}
};
bool is_palindrome(string& s)
{
string::iterator new_end = remove_if(s.begin(), s.end(), not1(good_char()));
s.erase(new_end, s.end());
string r = s;
reverse(r.begin(), r.end());
if (s == r)
{
return true;
}
return false;
}
int main()
{
string s;
cout<<"Enter a word or phrase: ";
getline(cin, s);
if (is_palindrome(s))
{
cout<<"You entered a palindrome"<<endl;
}
}