Palindrome/Read backward

I have to create a palindrome program that uses input and output files. I have to read in 30 names out of the 30 names 4 has to be palindrome and they must begin with the letter J(make up anything). I then have to put the names in order. I must check to see if the name is palindrome or not and if it is print the name.Here is part of the program, can someone help me please!
#include <iostream>
#include <string>
#include <fstream>

using namespace std;


ifstream infile;
ofstream outfile;

int main()
{

while(!infile.eof())
{
char name[100];


infile.open("palidromeJ.txt");
outfile.open("print.txt");



outfile << "Enter a name :"<<endl;

infile >> name;

int x = strlen(name)-1;



for(int i = 0; i <= x; i++)
{
if (name[i] == name[x-i])
{
continue;
}
else
{
outfile<<"Not palidrome"<<endl;
return 0;
}
}


outfile << "A Palidrome"<<endl;


}
infile.close();
outfile.close();
system("PAUSE");
return 0;
}

Last edited on
You should open a file then check if it is not eof!

That's the only thing that i noticed.
Last edited on
Topic archived. No new replies allowed.