This program is suppose to read a line of text and find out if its a palindrome or not(a palindrome is a line of text that has the same sequence of letters both forward and backward. but so far its only reading one line. and its not getting it right
here's the infile:

Madam I'M Adam.
Nix on NIXON.
A man, a plan, a canal, PANAMA.
"Lager,sir,is regal".
You can cage a swallow can't you? But you can't swallow a cage, can you?
Lisa Bonet ate no basil.


Please i need assistance.....
Thanks for stopping by

//Program Six
//Due Date: 30th April 2010
//This program read

#include<iostream>
#include<fstream>
using namespace std;

bool letter(char ch)
	{
		return('a'<= ch && ch <= 'z')||('A'<=ch && ch <='Z');
}
int main()
{
	ofstream outfile;
	ifstream infile;
	outfile.open("outfile.txt");
	infile.open("infile.txt");
	char line[80];
	bool palindrome;
	char ch;
	int little();
	int i = 0,size=0;

	infile>>ch;
		/*while(ch!.eof)*/
	while(ch!='.')
	{
		outfile<<ch;
		if(letter(ch))
			{
				line[i]=/*toupper*/(ch);
				i++;	
			}
			infile>>ch;
	}
				
		line[i]=line[size-i];
			palindrome = true;
		for(int i=0; i <=size/2; i++)
			if(line[i]=line[size-i])
				palindrome=false;
	if (palindrome)
		outfile<<"is a palindrome"<<endl;
	else
	outfile<<"is not a palindrome"<<endl;

	
		outfile.close();
		infile.close();
}

Dude the variable size is initialized to 0. You dont change its value any where in the program. Give it the value of string length at some point of the program

Sorry its supposed to be int size; not size = 0,

//Stephen Igbinedion
//Program Six
//Due Date: 30th April 2010
//This program read

#include<iostream>
#include<fstream>
using namespace std;

bool letter(char ch)
	{
		return('a'<= ch && ch <= 'z')||('A'<=ch && ch <='Z');
}
int main()
{
	ofstream outfile;
	ifstream infile;
	outfile.open("outfile.txt");
	infile.open("infile.txt");
	char line[80];
	bool palindrome;
	char ch;
	
	int i = 0,size;

	infile>>ch;
		/*while(ch!.eof)*/
	while(ch!='.')
	{
		outfile<<ch;
		if(letter(ch))
			{
				line[i]=/*toupper*/(ch);
				i++;	
			}
			infile>>ch;
	}
				
		line[i]=line[size-i];
			palindrome = true;
		for(int i=0; i <=size/2; i++)
			if(line[i]=line[size-i])
				palindrome=false;
	if (palindrome)
		outfile<<"is a palindrome"<<endl;
	else
	outfile<<"is not a palindrome"<<endl;

	
		outfile.close();
		infile.close();
}

To get the best help here, it's best to give us an idea of what the problem is, rather than making us guess. What do you need help with? What's going wrong?

Thanks. Its not accessing all the infile characters. its only accessing the first line. it printed out the first line "Madam I'M Adam". to the outfile saying its not a palindrome which is wrong.

The variable size .... You have not given it any value .... It should be initialized as the length of the string

even still its not accessing the rest of the infiles. and its still giving the only line. Madam I'M Adam. reads not a palindrome
thanks stopping by.

You come out of the while loop when you hit a period(.) Maybe that's why
Also for comparing the chars of the string ...you want to use == not =

Don't you need to ignore non-letters? For the sentence MADAM I'M ADAM, your code would compare:

M-M
A-A
D-D
A-A
M-" "
" "-M
I-'

would it not? Definitely not a palindrome.

Thanks , but am stuck on how to go about it cos i wrote this
while(ch!='.') for the compiler to read the ch and stop when it comes across a period. and it would more be helpful to write the numbers of the code in ur replies. thanks though

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.