i am testing five strings to see if they are palindrone. my program is running, but in my outfile, it is saying that everything is "Not Palindrone"....which isn't correct. and the strings look messed up when displayed also. i don't know what is wrong with my code, but i think my problem lies within my "for loop." i am trying to successfully reverse the arrays so it can compare oldstr and newstr. any help appreciated. thank you.
Source Code:
Code:
#include<iostream.h>
#include<fstream.h>
#include<string.h>
ofstream outfile;
ifstream infile;
void main()
{
infile.open ("rh1165p.dat");
outfile.open ("out5.txt");
char oldstr[26], newstr[26];
while (infile)
{
infile.getline(oldstr,26);
infile>>ws;
outfile<<oldstr<<" ";
int counter=0;
for (int psn=strlen(oldstr)-1; psn>=0; psn--)
{
counter++;
newstr[counter]=oldstr[psn];
}
outfile<<newstr;
if (strcmp(oldstr,newstr)==0)
outfile<<" ==> Palindrone"<<endl<<endl;
else
outfile<<" ==> Not Palindrone"<<endl<<endl;
}
}
Here is my "rh1165p.dat" file i am pulling from:
152215
dandy randy
Able was I ere I saw elbA
RemeR
200211112002
And here's my final output in my outfile so far:
152215 Ç512251 ==> Not Palindrone
dandy randy Çydnar ydnad ==> Not Palindrone
Able was I ere I saw elbA ÇAble was I ere I saw elbA^A@^A ==> Not Palindrone
RemeR ÇRemeRwas I ere I saw elbA^A@^A ==> Not Palindrone
200211112002 Ç200211112002re I saw elbA^A@^A ==> Not Palindrone
Code Tags added by Kermi3