c-string Palindrome using a do-while loop
Feb 21, 2017 at 3:10am UTC
I'm trying to figure out what equation should I do (after my if statement) to see if a c-string is palindrome or not using a do-while loop.
Thanks in advance.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
#include <iostream>
#include <string.h>
#include <ctype.h>
using namespace std;
void main()
{
const int StrnChar(80);
char Line[StrnChar + 1];
do {
cout << "Enter a string: " ;
cin.getline(Line, StrnChar + 1);
if ((strcmp(Line, StrnChar + 1) == 0);
{
cout << " Not Palindrome " ;
}
else
{
cout << " Palindrome " ;
}
} while (strcmp(Line, "END" ) != 0);
}
Feb 21, 2017 at 8:01am UTC
What you need is another variable like Line
. Before the if
you copy the entered Line
backwards to that new variable and use that variable (not StrnChar
) in strcmp(...) in order to determine whether it's a palindrom or not.
Topic archived. No new replies allowed.