Hi everyone.

I'm extremely new to this. It's my first programming course, period. I realize I probably needed a load of pre-reqs, but for some reason, I was advised to take Intro to C++ so...

So far, I've been doing well! However, this latest project has me stumped...

The jist of it:

Read lines from an input file, reverse, compare, find palindrome, and write it back out to the input file.

So far:

#include<fstream>
#include<iostream>
#include<string>
#include<cctype>
usingnamespace std;
#define SIZE 80
char palinCan[SIZE+1];
char reverse[SIZE+1];
int i = 1,a = 0, j ,q = 0,num = 0;
char reversal(char palinCan[SIZE]);
char b;
 
int main()
{
//int palindrome(char[]);
 
ifstream in;
ifstream infile;
infile.open("file.txt.txt", ios::in);
if (infile.fail())
{
cerr << "Couldn't open file..." << endl;
return 0;
}
do{
 
infile.getline(palinCan, SIZE+1);
strcpy_s(reverse, palinCan);
/* if(palindrome(reverse))
cout << storage << reverse << "It's a palindrome" << endl; 
else 
cout << "Nope" << endl; // I am getting "does not evaluate to function taking #of arguments here */
cout << palinCan << reverse << endl;
 
 
}while (!infile.eof());
}
char reversal()
{
for(j = strlen(palinCan); j >= 0 ; j--){
cin >> reverse[SIZE];}
return reverse[SIZE];
}

I don't know how to make a functioning... function to reverse the loop and return the result into the reversal array for comparison. I've tried a few variations, but none of them worked.

Once I have the reverse of the string stored in the reverse array, I should be able to make a comparison function with it, and have it return a simple true or false.

I appreciate any help...

This is a c++ program, why are you using c-style char arrays. Unless your instructore requires it you should probably be using std::string as input buffer.

You do loop is all wrong. Use a while loop instead for better control.

std::string inbuf;
while( getline(infile,inbuf) )
{
   // blabla
}

now all you have to do is creae another std::string object and copy the caracters backwards from inbuf into it.

commented: Good job, Ancient Dragon :) --joeprogrammer +3

This is a c++ program, why are you using c-style char arrays. Unless your instructore requires it you should probably be using std::string as input buffer.

You do loop is all wrong. Use a while loop instead for better control.

std::string inbuf;
while( getline(infile,inbuf) )
{
   // blabla
}

now all you have to do is creae another std::string object and copy the caracters backwards from inbuf into it.

How do I copy the reverse/backwards into it though? That's the primary problem I'm having now... getting the reverse of a string and storing that for comparison.

do you have to reverse just the words?
"Hello World" becomes "World Hello"

or reverse all the letters? Reversing the letters is easy -- reversing words becomes a little more complex. As I mentioned in my previous post, you need to create a second string and copy the characters to it in reverse order -- create a loop that starts at the end of the string and decrement instead of increment the loop counter. For example:

for(int i = inbuf.length()-1; i >= 0; --i)
{

}

do you have to reverse just the words?
"Hello World" becomes "World Hello"

or reverse all the letters? Reversing the letters is easy -- reversing words becomes a little more complex.

the letters. The letters have to be reversed so that it can be compared to the normal line.

the letters. The letters have to be reversed so that it can be compared to the normal line.

Good -- that simplifies the program. See my previous post. The rest you will have to figure out because I don't want to write your program for you.

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.